🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9457

Re: sizeof (int) - 1

#9457
From: Gary M. Samuelson
Date: Wed, 01 Oct 1986 18:25
23 lines
1383 bytes
>> 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

>> The unix compiler does it the second way, for when it sees the '-' it
       ------------- (speaking of ambiguous)
>> sets the precedence for that character ASSUMING it will be used as a
>> binary operator.

>There is nothing ambiguous about it.
>K&R p188:
>"The construction   sizeof(type)  is taken to be a unit, so the
>expression  sizeof(type)-2  is the same as (sizeof(type))-2."

You're both partially right, and partially wrong.  The expression
would be ambiguous, if not for the disambiguating rule where the
compiler is not *assuming* that the minus sign is binary, but
*deciding* that it is.

Gary Samuelson
Technical Details
Message-ID: <1217@bunker.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!nike!ll-xn!mit-amt!mit-eddie!genrad!decvax!ittatc!bunker!garys
References: <102500008@uiucuxc> <271@hoqam.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!nike!ll-xn!mit-amt!mit-eddie!genrad!decvax!ittatc!bunker!garys
From: garys@bunker.UUCP (Gary M. Samuelson)
Newsgroups: net.lang.c
Subject: Re: sizeof (int) - 1
Message-ID: <1217@bunker.UUCP>
Date: Wed, 1-Oct-86 14:25:58 EDT
Article-I.D.: bunker.1217
Posted: Wed Oct  1 14:25:58 1986
Date-Received: Sat, 4-Oct-86 02:08:20 EDT
References: <102500008@uiucuxc> <271@hoqam.UUCP>
Reply-To: garys@bunker.UUCP (Gary M. Samuelson)
Organization: Bunker Ramo, Trumbull Ct
Lines: 23