sizeof on a word-oriented machine
Norman Diamond
diamond at csl.sony.co.jp
Thu Nov 16 19:14:34 AEST 1989
Consider a machine where each 4-byte word has an address.
char x[37];
int q;
q = sizeof x / sizeof (char);
What is sizeof x?
If sizeof x is 40 (since 40 bytes are reserved for x) then the example
on page 46 lines 12 to 13 (section 3.3.3.4) is violated.
If sizeof x is 37 then a user might do:
char *two_xs;
two_xs = malloc (2 * sizeof x);
and get screwed because only 76 bytes will be allocated (2 * 37 rounded
up to a multiple of 4) when 80 are really needed.
I think 40 is the most reasonable value for sizeof x. Is the standard's
example wrong? May it be ignored?
--
Norman Diamond, Sony Corp. (diamond%ws.sony.junet at uunet.uu.net seems to work)
Should the preceding opinions be caught or | James Bond asked his
killed, the sender will disavow all knowledge | ATT rep for a source
of their activities or whereabouts. | licence to "kill".
More information about the Comp.std.c
mailing list