www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - sizeof

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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?
Jan 01 2011
parent reply "Manfred_Nowak" <svv1999 hotmail.com> writes:
Ellery Newcomer wrote:

 d code prints 12

prints 16 ( DMD 2.051 on win32) -manfred
Jan 01 2011
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
curious. prints 12, DMD 2.051 linux

On 01/01/2011 06:15 PM, Manfred_Nowak wrote:
 Ellery Newcomer wrote:

 d code prints 12

prints 16 ( DMD 2.051 on win32) -manfred

Jan 01 2011
parent "Manfred_Nowak" <svv1999 hotmail.com> writes:
Ellery Newcomer wrote:

 prints 12, DMD 2.051 linux

So we have: ( linux32 , dmd 2.051) -> 12 ( linux32 , gdc) -> 12 ( linux64 , gdc) -> 12 ( linux64 , ldc) -> 16 ( win32 , dmd 2.051) -> 16 ( cygwin32, gdc) -> 16 Congrats Ellery: this looks like a stairway to hell. -manfred
Jan 02 2011