Various questions about Ada

I have a few Ada questions that I’ll just summarize in one post.

If I always have to completely rewrite a file, then it makes no difference whether I use Open or Create. Is that correct or did I miss something?

Currently I use Stream_IO to write files, the files contain different data types. Do other writing methods, such as Sequential_IO, produce smaller files that justify the extra effort to use them? Or are they practically all equally efficient?

I use Pure, Preelaborate and Elaborate_Body whenever possible. However, I have some files that don’t allow Pure/Preelaborate and since they don’t have a body, Elaborate_Body isn’t possible either. However, I would still like to know if there is a circular dependency. Are there any other options besides giving all files a body?

Is there a standard function that returns the number of elements in an enum subtype, or do I have to write it myself?

  1. After you close the file, there should be no difference. While you are writing the file, the externally visible contents of the file may be different.
  2. In what way is a file’s size related to “efficiency”?
  3. If you have a circular dependency, you will know it.
  4. There is no standard function for this. For an enumeration subtype E, this is
    E'Pos (E'Last) - E'Pos (E'First) + 1
  1. Efficient in producing small files? The word efficient may have been chosen a little unfavorably here.
  2. And how?

The binding stage will report failure. The last time I had this (many years ago) the report was accompanied by a long list of packages which was supposed to help finding the problem. To be fair, I think it did - after much headscratching

I don’t know if there is an intended efficiency difference between sequential_io and stream_io. It would probably depened on the implementation and need benchmarking. I think they were more likely designed with code writing efficiency in that if you already had a stream and wanted to write a binary file, you can use stream_io, but if you didn’t have a stream and just wanted to write a type to a file, then you could use sequential_io. It wouldn’t surprise me if an implementation used one to create the other even, though I don’t know if they do.

Sequential IO was in Ada 83, Stream IO came along in Ada 95.