comp.lang.ada
 help / color / mirror / Atom feed
From: "Eric G. Miller" <egm2.NOSPAM@jps-NOSPAM.net>
Subject: Re: Import a type from C
Date: Fri, 10 Jan 2003 03:48:48 GMT
Date: 2003-01-10T03:48:48+00:00	[thread overview]
Message-ID: <AorT9.2511$Qr4.233299@newsread1.prod.itd.earthlink.net> (raw)
In-Reply-To: <avi2mt$75l$1$830fa17d@news.demon.co.uk>

Rupert Pigott wrote:
> "Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
> news:u7kfqjnvv.fsf@gsfc.nasa.gov...
> 
>>"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:
>>
>>
>>>    pragma Convention( C, My_Data );
>>>
>>>The Convention pragma can be used to specify that this record type
> 
> should be
> 
>>>laid out in the same way that a C compiler would.
>>
>>Note that "a C compiler" really means "the C compiler that the Ada
>>compiler knows about, with its default command line args". For
>>example, GNAT will assume Gnu C, _without_ -fpacked. ObjectAda
>>probably assumes MS C, again without the "packed" flag. That has
>>caused me some major problems, when linking against C code compiled
>>_with_ the -fpacked flag.
>>
>>So I always use a rep spec, instead of relying on Convention (C). Then
>>I write some C code that checks the struct size, to be sure there is
>>no padding.
> 
> 
> Perhaps I'm overly pessimistic here... IIRC there is no guarantee
> of the order of members within a structure in C either. One of those
> little gotchas (along with no alignment control) that **** portable
> code and force you to go the long way around...

You're high 8^)  The order of members in a C struct is always as specified
in the definition.  Furthermore, a pointer to a struct is always
guaranteed to resolve to a pointer to the first member.  The alignment
of any subsequent members is implementation defined.  Portable C code
would never pack a struct to begin with (an inherently unportable practice).

-- 
echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse




  reply	other threads:[~2003-01-10  3:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-06 19:48 Import a type from C Francisco Santoyo
2002-11-06 20:06 ` Frank J. Lhota
2002-11-06 23:10   ` Stephen Leake
2003-01-08 20:46     ` Rupert Pigott
2003-01-10  3:48       ` Eric G. Miller [this message]
2003-01-14  4:47       ` David Thompson
2002-11-07  7:16 ` Victor Porton
2002-11-07 13:47   ` Stephen Leake
2002-11-07 16:03   ` Frank J. Lhota
2002-11-07 16:20     ` Robert A Duff
2002-11-08 14:51       ` Stephen Leake
2002-11-07 19:00 ` chris.danx
2002-11-08  4:02 ` Victor Porton
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox