Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why is an exception raised when giving a default discriminant?

0
10 Posted

Why is an exception raised when giving a default discriminant?

0

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123