Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: 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 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---/