From: David Thompson <dave.thompson2@verizon.net>
Subject: Re: Interfacing to C: big structures
Date: Mon, 10 Mar 2008 01:38:30 GMT
Date: 2008-03-10T01:38:30+00:00 [thread overview]
Message-ID: <jam8t31vk9pgne5mo6aesajhdta8k1l1c7@4ax.com> (raw)
In-Reply-To: wcck5krjigf.fsf@shell01.TheWorld.com
On Tue, 26 Feb 2008 20:28:48 -0500, Robert A Duff
<bobduff@shell01.TheWorld.com> wrote:
> "Alex R. Mosteo" <amosteo@unizar.es> writes:
> > And, finally, is adding an alignment clause enough to solve this issue?
> > If so, how do you query the alignment of a C datatype?
>
> I'm not a C expert, but I don't think there's any easy way.
>
Easy is a matter of opinion, and not very elegant, but possible:
#include <stddef.h>
struct S { whatever };
size_t /* or other u-int type */ Alignment_for_S (void)
{
struct trick { char x; S y; } /* type only no instance */;
return offsetof (struct trick, y);
}
This isn't guaranteed to be minimal, but it is sufficient.
- formerly david.thompson1 || achar(64) || worldnet.att.net
next prev parent reply other threads:[~2008-03-10 1:38 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-25 21:17 Interfacing to C: big structures Maciej Sobczak
2008-02-25 23:26 ` Randy Brukardt
2008-02-25 23:26 ` Randy Brukardt
2008-02-27 13:23 ` Maciej Sobczak
2008-02-25 23:26 ` Randy Brukardt
2008-02-25 23:43 ` Robert A Duff
2008-02-26 13:53 ` Stephen Leake
2008-02-26 21:12 ` Randy Brukardt
2008-02-26 2:36 ` Steve
2008-02-26 12:00 ` Alex R. Mosteo
2008-02-26 14:05 ` Robert A Duff
2008-02-26 15:19 ` Alex R. Mosteo
2008-02-26 15:33 ` Robert A Duff
2008-02-26 16:21 ` Alex R. Mosteo
2008-02-27 1:28 ` Robert A Duff
2008-03-10 1:38 ` David Thompson [this message]
2008-02-26 17:35 ` Adam Beneschan
2008-02-26 19:47 ` Simon Wright
2008-02-26 21:14 ` Randy Brukardt
2008-02-27 1:40 ` Robert A Duff
2008-02-27 17:12 ` Adam Beneschan
2008-02-27 20:37 ` Simon Wright
2008-02-28 11:30 ` Alex R. Mosteo
2008-02-28 15:53 ` Robert A Duff
2008-02-29 10:45 ` Alex R. Mosteo
2008-02-27 1:37 ` Robert A Duff
2008-02-27 13:49 ` Maciej Sobczak
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox