Re: volatile vs aliased

"REH" <spamjunk@xxxxxxxxxxx> wrote in message
> That's good stuff. Will it still apply when the address is to a
> subprogram? Can Address_to_Access_Conversions be instantiated with a
> subprogram?


> That's what I've been trying to do, but I don't know how
> to make a generic that takes an access to an arbitrary subprogram type.
> So, I think I am "stuck" using the for X'address specification.

For that, I generally use an appropriate access-to-subprogram type (with the
correct profile), and a dummy "void" access-to-subprogram, and an

For instance, "void" is cast as a parameterless procedure with the correct
convention. Say we want a access-to-function:

type Void_Subprogram is access procedure;
pragma Convention (C, Void_Subprogram);
-- Use this in the "generic" interfacing routines.

type A_Func is access function (A : Integer) return Integer;
pragma Convention (C, A_Func);

function Convert is new Unchecked_Conversion (Source => Void_Subprogram,
Target => A_Func);

You do have to know that the C compiler uses the same representation for all
access-to-subprogram types (which is likely, more likely than it is for
Ada), but that's the only assumption that you need to make.

You can also use System.Address in place of Void_Subprogram (using the same
Unchecked_Conversion), but it may not have the appropriate representation on
some targets. (One example was the U2200 compiler we worked on --
access-to-subprogram values included an extra link word along with the
address, so an Unchecked_Conversion from Address wouldn't work. That was
required by the underlying system; I don't think there was a way around it.)