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: Eric Botcazou <ebotcazou at adacore dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: 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 12:46:30 +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>
> I suspect Ada needs something like this already. I expect the following
> to work (although it is quite hideous).
>
> with System;
>
> 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;
> begin
> return Foo_2;
> end Bar;
>
> end Import;
System.Address is an integer though so that will always work (on 32-bit
architectures) without special support. And, no, Ada doesn't need this
general capabilitly, address frobbing like above is at your own risk and
you certainly don't want to use access (pointer) types with it anyway.
That being said, there is indeed a related issue with Ada on m68k because,
when you have a C function that returns a pointer (typically malloc), you
generally import it in Ada as System.Address:
function malloc (Size : size_t) return System.Address;
pragma Import (C, malloc, "malloc");
so the C and the Ada sides don't agree on the return register...
--
Eric Botcazou