Why is an exception raised when giving a default discriminant?
Let’s assume you would like to model varying-length strings: type V_String (Size : Natural := 0) is record S : String (1 .. Size); end record; (from Robert Dewar) When you give a default discriminant, then one method (I actually think it is the preferred method) of implementation is to allocate the maximum possible length. Since your discriminant is of type Natural, this clearly won’t work! GNAT may compile it, but it won’t run it, and indeed I consider it a GNAT bug (on the todo list) that no warning is issued at compile time for this misuse. Some compilers, notably Alsys and RR, have at least partially “solved” this problem by introducing hidden pointers, but this to me is an undesirable implementation choice. First, it means there is hidden heap activity, which seems undesirable. In a language where pointers are explicit, it is generally a good idea if allocation is also explicit, and certainly for real-time work, hidden anything is worrisome. Second, it is not easy to do uniformly.
Related Questions
- I have a number of applets in the default package that I obfuscate separately. How do I stop Zelix KlassMaster from giving them the same name (e.g."a.class")?
- If unnormalized data is found, should an exception be raised, or the data be normalized forthwith, or only if necessary?
- Why is an exception raised when giving a default discriminant?