โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Can I instantiate a generic within the same unit in Ada?

It doesn't seem like this is possible, but I haven't seen a definitive answer. What I want to do is define a generic subprogram with some generic formal parameters and instantiate it in the same package, like the following simplified and untested example:

generic
    Proc_Address : access System.Address;
    type Param_1_Type (<>) is private;
procedure Procedure_IP(Param_1 : Param_1_Type);

Instance_1_Address : System.Address := ...
procedure Instance_1 is new Procedure_IP(Instance_1_Address, type_1);
Instance_2_Address : System.Address := ...
procedure Instance_2 is new Procedure_IP(Instance_2_Address, type_2);
--etc

But this kind of thing keeps resulting in those "access before elaboration" errors. I can't seem to find any pragmas that will affect elaboration of a single subprogram; seems it has to be the whole package. Attempts to move the generic subprogram into a separate package have proven more troublesome than I had hoped because the specific stuff I want the function to do is closely related to other things happening in the same package.

Is there any way to resolve the elaboration order issue, so that I can keep the declaration and instantiations in the same package?

Option B is to rework this in a different way, like maybe passing a function pointer to a non-generic function or something, but doing it as a generic seems to be the cleanest way to go about it, especially since I'll need to refer to each of the intended instances a lot.

Why does elaboration require the programmers attention in Ada? [closed]

I stumbled upon an in depth explanation of elaboration, it's standardized ordering scheme, and the options available to the programmer for controlling it in unsuccessful cases.

http://www.cs.uni.edu/~mccormic/4740/documentation/elaboration

First, it's still unclear why elaboration needs to be addressed by the programmer at all. I've never dealt with it in any other language such as C, Pascal or C++ where the order of allocation and assignment variables, as well as code execution, are rarely of concern. Why isn't it automatically handled and what benefits does it offer to the developer?

Second, elaboration failures are often not detected statically, but at runtime only as a "program error" exception. I find it a bit disconcerting, considering it can suddenly occur in a number of scenarios, including changes in the runtime, the code base, the compiler or its version. It seems to belie Ada's core tenet of code safety and reliability.

โŒ
โŒ