Jonathan Adams wrote:
On Wed, Feb 11, 2009 at 10:37:27AM -0500, Jeff Trawick wrote:
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.

I assume this is on an x86 box;  are you in 32-bit or 64-bit mode?

yes, x86 and 32-bit

OpenSolaris 2008.11 snv_101b_rc2 X86
pfexec /usr/sbin/dtrace -32 -s ./foo.d 1234

Here's a subset of the exact definitions, up until the point of an alignment discrepancy, which I've kludged with char[8].

typedef int64_t apr_time_t;
typedef struct request_rec request_rec;

struct request_rec {
void *pool;
void *connection;
void *server;
request_rec *next;
request_rec *prev;
request_rec *main;
char *the_request;
int assbackwards;
int proxyreq;
int header_only;
char *protocol;
int proto_num;
const char *hostname;
/* apr_time_t request_time; */ <- desired mapping
char request_time[8];

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

Reply via email to