🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1754

Re: [m]allocation question

#1754
From: Doug Gwyn
Date: Thu, 27 Sep 1990 21:56
11 lines
951 bytes
In article <UaxqffS00Vtq8akksB@andrew.cmu.edu> ghoti+@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.
Technical Details
Message-ID: <13946@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!adm!smoke!gwyn
References: <UaxqffS00Vtq8akksB@andrew.cmu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: [m]allocation question
Message-ID: <13946@smoke.BRL.MIL>
Date: 27 Sep 90 21:56:16 GMT
References: <UaxqffS00Vtq8akksB@andrew.cmu.edu>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Lines: 11