comp.lang.ada
 help / color / mirror / Atom feed
* Determining alignment
@ 2009-02-01 12:15 sjw
  0 siblings, 0 replies; only message in thread
From: sjw @ 2009-02-01 12:15 UTC (permalink / raw)


GNAT has the non-standard attribute "Standard'Maximum_Alignment
(Standard is the only permissible prefix) [which] provides the maximum
useful alignment value for the target. This is a static value that can
be used to specify the alignment for an object, guaranteeing that it
is properly aligned in all cases."

My problem is to create (private) representations (in the TASH
bindings) for C structs which need to be on the stack (ie, declared by
the user) whose contents depend on macros defined in tcl.h and friends
and which therefore aren't easily determined by reading the source.

I already have a scheme to use a Tcl script to create a C program
which creates a package Tcl_Record_Sizes which defines suitable
constants (using sizeof()). The binding then declares arrays of bytes
of these lengths and specifies the alignment using
Standard'Maximum_Alignment.

This clearly isn't portable. One solution would be to change
Tcl_Record_Sizes to include the actual alignment using offsetof from
<stddef.h> --

#define TYPE_ALIGNMENT( t ) offsetof( struct { char x; t test; },
test )

which I vaguely remembered and found again (slightly deprecated) at
http://stackoverflow.com/questions/364483/determining-the-alignment-of-cc-structures-in-relation-to-its-members

Any better suggestions?

TIA,

--S



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-01 12:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-01 12:15 Determining alignment sjw

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