🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9466

Re: sizeof (int) - 1

#9466
From: Pedz Thing
Date: Wed, 01 Oct 1986 21:06
25 lines
1472 bytes
In article <102500008@uiucuxc> grayson@uiucuxc.CSO.UIUC.EDU writes:
>
>It is interesting that the expression
>	sizeof (int) - 1
>is ambiguous in C, for it can be parsed as
>	sizeof ((int)(- 1))
>or as
>	(sizeof(int)) - 1
>

At first, I thought this note was really stupid.  I had the idea that
unary minus was down at a different level from the other unary
operators.  Then as I looked more and more into it, I came to these
conclusions.  First, what the compiler does is correct because this
exact case is mentioned in the K & R (Last paragraph of section 7.2 in
Appendix A, page 188).  Second, this is a special case.  Sizeof, type
cast, and unary minus are all at the same precedence and they
associate right to left.  Thus the normal interpretation would be
(sizeof ((int) (-1))).  This is not the correct interpretation however
as I just mentioned.
-- 
Perry Smith
ctvax ---\
megamax --- bobkat!pedz
pollux---/
Technical Details
Message-ID: <142@bobkat.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cuae2!ltuxa!we53!sw013b!dj3b1!killer!ndmce!pollux!bobkat!pedz
References: <102500008@uiucuxc>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cuae2!ltuxa!we53!sw013b!dj3b1!killer!ndmce!pollux!bobkat!pedz
From: pedz@bobkat.UUCP (Pedz Thing)
Newsgroups: net.lang.c
Subject: Re: sizeof (int) - 1
Message-ID: <142@bobkat.UUCP>
Date: Wed, 1-Oct-86 17:06:29 EDT
Article-I.D.: bobkat.142
Posted: Wed Oct  1 17:06:29 1986
Date-Received: Sat, 4-Oct-86 10:31:24 EDT
References: <102500008@uiucuxc>
Reply-To: pedz@bobkat.UUCP (Pedz Thing)
Organization: Digital Lynx; Dallas, TX
Lines: 25