sizeof

Ellery Newcomer ellery-newcomer at utulsa.edu
Sat Jan 1 15:43:00 PST 2011


Hello. Been trying to link to some C code with gdc on 64 bit, and I've 
been racking my brain over the following:

//tok.d
import std.stdio;
struct x {
     union _u_{
         ulong uq;
         struct _s_ {
             ushort dw;
             uint dd;
         };
         _s_ s;
     };
     _u_ u;
     ushort zz;
}

void main(){
     writeln(x.sizeof);
}


//tok.c
#include <stdint.h>
#include <stdio.h>

struct x {
     union {
         uint64_t uq;
         struct {
             uint16_t dw;
             uint32_t dd;
         } s;
     } u;
     uint16_t zz;
};

void main(){
     printf("%d\n", sizeof(struct x));
}


the d code prints 12, and the C code prints 16. Should I be expecting 
the two to be the same?


More information about the Digitalmars-d-learn mailing list