sizeof on a word-oriented machine
Doug Gwyn
gwyn at smoke.BRL.MIL
Sat Nov 18 02:59:12 AEST 1989
In article <11135 at riks.csl.sony.co.jp> diamond at ws.sony.junet (Norman Diamond) writes:
-Consider a machine where each 4-byte word has an address.
- char x[37];
-What is sizeof x?
37.
-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.
No, only 2*37 bytes are needed. Arrays are not padded.
-I think 40 is the most reasonable value for sizeof x. Is the standard's
-example wrong? May it be ignored?
The example is right. Feel free to ignore it.
More information about the Comp.std.c
mailing list