TC bug in sizeof()?

Duncan Murdoch dmurdoch at watstat.waterloo.edu
Fri Feb 16 04:47:49 AEST 1990


A friend of mine has found something surprising in TC.  Neither of us knows
C well enough to know for sure that this is a bug, but it looks like one.
As illustrated in the program below, if a structure is an odd size, and
is compiled with Word alignment, the sizeof function rounds the size up
one byte.  

Is this a bug?

Sample program:

struct test
  { char a;
    char b;
    char c;
  } structure;

main()
{
  printf("Size of structure= %d\n",sizeof(structure));
}

This prints a 3 if compiled with byte alignment, an 4 if compiled with word
alignment.

Thanks for any help.  Please post to comp.sys.ibm.pc, or email to me, as
you prefer.

Duncan Murdoch



More information about the Comp.lang.c mailing list