RFC: Support non-standard extension (call via casted function pointer)

Arnaud Charlet charlet@adacore.com
Thu Jan 28 12:17:00 GMT 2016


> > package Import is
> > 
> >    function Foo return System.Address;
> >    pragma Import (C, Foo);
> > 
> >    function Bar return Integer;
> > 
> > end Import;
> > 
> > package body Import is
> > 
> >    function Bar return Integer is
> >       function Foo_2 return Integer;
> >       pragma Import (C, Foo_2);
> >       for Foo_2'Address use Foo'Address;

BTW the proper idiom would be instead:

       function Foo_2 return Integer;
       pragma Import (C, Foo_2, "foo");

to import the same C function with two different types.

But as Eric said, users should use this at their own risk, and only on truly
compatible types, otherwise this is non portable and may break across compilers
or versions.

Arno



More information about the Gcc mailing list