This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: Support non-standard extension (call via casted function pointer)
- From: Arnaud Charlet <charlet at adacore dot com>
- To: Eric Botcazou <ebotcazou at adacore dot com>
- Cc: Florian Weimer <fweimer at redhat dot com>, gcc at gcc dot gnu dot org, Richard Biener <richard dot guenther at gmail dot com>, Thorsten Otto <halgara at yahoo dot de>, Michael Karcher <debian at mkarcher dot dialup dot fu-berlin dot de>, John Paul Adrian Glaubitz <glaubitz at physik dot fu-berlin dot de>, Debian m68k <debian-68k at lists dot debian dot org>, Andreas Schwab <schwab at linux-m68k dot org>, Matthias Klose <doko at debian dot org>
- Date: Thu, 28 Jan 2016 13:17:26 +0100
- Subject: Re: RFC: Support non-standard extension (call via casted function pointer)
- Authentication-results: sourceware.org; auth=none
- References: <56A7C307 dot 3010701 at mkarcher dot dialup dot fu-berlin dot de> <CAFiYyc0fAj3Dq6SEySEf93_Fx0heK5nh9VRrY-u8VNDePyqYdw at mail dot gmail dot com> <56A9E966 dot 3090708 at redhat dot com> <1463480 dot TdGLKxFkk6 at polaris>
> > 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