[m]allocation question

Henry Spencer henry at zoo.toronto.edu
Thu Sep 27 04:03:32 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.

No; the operand of a sizeof is never evaluated.  The compiler notes its
type but does not generate code for it.  Beware:  this was not entirely
clear in K&R1 and some old compilers may violate the rule.
-- 
TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology
OSI: handling yesterday's loads someday|  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.std.c mailing list