Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!pantor!richard From: richard@pantor.UUCP (Richard Sargent) Newsgroups: comp.lang.c Subject: Re: The Dangers of sizeof Message-ID: <6.UUL1.3#5109@pantor.UUCP> Date: 12 Apr 89 18:48:16 GMT References: <2280@mentor.cc.purdue.edu> Organization: Pansophic Systems Inc, Graphics Product Company Lines: 29 acu@mentor.cc.purdue.edu (Floyd McWilliams) wrote in article <2280@mentor.cc.purdue.edu>: > In article <105@servio.UUCP> penneyj@servio.UUCP (D. Jason Penney) writes: > > [Discussion of how "sizeof (char) - 1" is 1 not 0.] > > Oh really? Then take a look at this: > > -- > [Script to prove it ain't so.] > -- > > "sizeof" may not be a function, but it does have a high precedence > (it's a unary operator). If what you posted were true, then everyone who > tried a "sizeof(foo) + CONST" under pre-ANSI standard C would have been > screwed; C didn't have a unary plus. > Quite right! I quote K&R, Section 7.2 Unary Operators, pages 187-188 (first edition). The very last paragraph of the section, on page 188, reads: "The construction sizeof( type ) is taken to be a unit, so the expression sizeof( type ) - 2 is the same as (sizeof( type )) - 2." QED. Richard Sargent Systems Analyst