Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!kenny From: kenny@m.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: sizeof a struc field Message-ID: <4700046@m.cs.uiuc.edu> Date: 25 Oct 89 17:25:00 GMT References: <7710@microsoft.UUCP> Lines: 39 Nf-ID: #R:microsoft.UUCP:7710:m.cs.uiuc.edu:4700046:000:1855 Nf-From: m.cs.uiuc.edu!kenny Oct 25 12:25:00 1989 Hey, wait a minute here. Is it just the constant NULL that can't be `dereferenced' in a sizeof expression, or is it any possibly invalid pointer? The discussion seems to indicate that the common idiomatic macro definition #define NEW(p) ((p) = malloc_and_check ((size_t) (sizeof *(p)))) (assuming that malloc-and-check never returns NULL, but throws a signal, longjmps, or something), is illegal under the proposed standard, because it dereferences the uninitialized pointer p. I find it hard to believe that this behavior was the intent of the Committee. If this interpretation is correct, I can still live with it by making a NEW macro for every type (typeof wasn't accepted, so I can't determine the size of the object without knowing the name of the type, unless I can write sizeof *p), or by passing the type name as a macro parameter, but it's pretty bogus. I hope at least that the Standard doesn't require that I go out of my way to make this NOT work. I can't imagine any way that a sane compiler writer could have this fail, since you never even need to load the pointer p -- all the discussion of possible faults upon loading a pointer into a register doesn't apply, since this expression never examines the value of the pointer at all. I would submit that `dereferencing' a pointer should mean reading from or writing into the location to which it points. Just putting a * or -> on it doesn't do this in C. Kevin | / o Kevin Kenny KB9DLU (217) 333-5821 |< /) | | | |/\ Department of Computer Science o , o , | \ X_ \/ | | | University of Illinois 40 07 N 88 13 W kenny@cs.uiuc.edu 1304 W. Springfield Ave. uunet!uiucdcs!kenny Urbana, IL 61801 AD ASTRA PER ARDUA k-kenny@uiuc.edu kenny%cs@uiucvmd.bitnet