I did some experimenting, and it appears to me that C (gcc) and DTrace
behave the same way, as long as you compare the executions in the same
addressing mode.

Gcc defaulted to -m32, which pads after the pointer, because the long
long wants to align on a 64 bit boundary.  D defaults to 64 bit, so I
used the -32 option and got the same results.  The whole structure is 24
bytes, but the fields are 4, 4, 4, and 8.

Using D's default 64 bit mode, and using the -m64 option in gcc, the
structure was still 24 bytes, but the fields were 4, 4, 8, and 8,
because the pointer is now 64 bits wide:  no padding.

Chip



> -----Original Message-----
> From: dtrace-discuss-boun...@opensolaris.org [mailto:dtrace-discuss-
> boun...@opensolaris.org] On Behalf Of Jeff Trawick
> Sent: Wednesday, February 11, 2009 9:37 AM
> To: dtrace-discuss@opensolaris.org
> Subject: Re: [dtrace-discuss] how to get DTrace to use the same
> structurefield alignment as C?
> 
> Jeff Trawick wrote:
> > Is there a pragma to turn off padding or some other mechanism
besides
> > dummying up fields to make them char[] to disable padding?
> 
> Here's a better explanation of the issue around my particular example:
> 
> I have a structure which contains some 64-bit integers.
> 
> struct some_api_rec {
> int x;
> int y;
> char *z;
> int64_t important_field;
> }
> 
> In C, important_field is at offset 0x0C (no padding between z and
> important_field).
> In D, important_field is at offset 0x10 (4 bytes of padding in front
of
> important_field to align it for performance, apparently).
> 
> This makes it problematic to use the C structure definition in D
> scripts. The C definition can't be changed.
> 
> If I change important_field to
> 
> char important_field[8];
> 
> the field alignment is fixed, but then important_field will be hard to
> use in D scripts.
> 
> _______________________________________________
> dtrace-discuss mailing list
> dtrace-discuss@opensolaris.org


_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

Reply via email to