comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Importing C structs?
Date: 31 Jul 2003 20:16:21 +0100
Date: 2003-07-31T20:16:21+01:00	[thread overview]
Message-ID: <x7vispi4id6.fsf@smaug.pushface.org> (raw)
In-Reply-To: bgbmgb$rd71@cui1.lmms.lmco.com

"Xenos" <dont.spam.me@spamhate.com> writes:

> We do this sort of think all the time.  Just create an Ada record
> that is properly rep. spec'd according to the way your C compiler
> does its structs.  If the parameter is a pointer to a struct use
> either System.Address or an access type.

I'm pretty sure GNAT will do the Right Thing here (ie pass the address
of the record parameter). I suppose there might be problems with very
small arrays on architectures where these are passed in registers? but
since the Ada and C compilers have the same backend you are quite
likely to be lucky. pragma Convention (C, ) means "do what the C
compiler expects", after all.

The trouble with rep clauses where the C side has none, or hasn't used
them, is that you only need to move to a different architecture
(PowerPC vs i86) for it all to go out of the window.

If you are sending the packets over a network, of course, it's more
difficult.

> Unfortunately, there is no portable way to do it.  But you usually
> don't run into trouble unless your structs would have misaligned
> fields.  The compiler avoids this by creating "holes."  Some C
> compilers give you limited control of the packing, but again, its
> not portable.

With GNAT there's -gnatR which tells you what the representation
actually is.



  reply	other threads:[~2003-07-31 19:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 20:03 Importing C structs? Freejack
2003-07-30 20:52 ` chris
2003-07-30 21:26   ` Freejack
2003-07-30 23:50   ` tmoran
2003-07-31 10:53     ` chris
2003-08-04 14:33     ` Andreas Almroth
2003-08-04 15:16       ` Samuel Tardieu
2003-08-04 20:07         ` Randy Brukardt
2003-07-31 17:14   ` Warren W. Gay VE3WWG
2003-08-12  0:02     ` chris
2003-07-31 18:17   ` Xenos
2003-07-31 19:16     ` Simon Wright [this message]
2003-07-31 20:17       ` Samuel Tardieu
2003-07-31 20:40       ` Xenos
2003-07-30 23:14 ` Ching Bon Lam
2003-07-31  0:07   ` tmoran
2003-07-31  5:35   ` Matthew Heaney
2003-07-31  7:46     ` Freejack
2003-07-31  9:27       ` Martin Dowie
2003-07-31 21:41         ` Freejack
2003-08-01  7:39           ` Martin Dowie
2003-07-31 17:34       ` Matthew Heaney
2003-07-31 11:29     ` Ching Bon Lam
2003-07-31 16:59       ` Matthew Heaney
2003-07-31 17:32         ` Warren W. Gay VE3WWG
2003-07-31 17:13       ` Matthew Heaney
2003-07-31 17:40       ` Randy Brukardt
2003-07-31  5:21 ` Matthew Heaney
replies disabled

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