[m]allocation question

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Sep 28 07:56:16 AEST 1990


In article <UaxqffS00Vtq8akksB at andrew.cmu.edu> ghoti+ at andrew.cmu.edu (Adam Stoller) writes:
>        t = (struct node *) malloc(sizeof *t);
>Isn't *t garbage at the time the sizeof is performed - isn't this
>[almost?] de-referencing a NULL pointer.

We went through this about a year ago in a different guise.
The outcome of that discussion was that, since the argument to sizeof
is NOT evaluated, there is no attempt to access through that pointer,
and only the type (not the value) of the hypothetical result is
relevant.  Thus sizeof(*t) is obliged to work even if t contains a
garbage value.



More information about the Comp.std.c mailing list