Article View: net.lang.c
Article #9436Re: sizeof (int) - 1
From: BEATTIE
Date: Tue, 30 Sep 1986 12:49
Date: Tue, 30 Sep 1986 12:49
20 lines
1042 bytes
1042 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
>
> Think about it!
>
> The unix compiler does it the second way, for when it sees the '-' it
> 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."
Tom.
...!{decvax | ucbvax}!ihnp4!hoqax!twb
Technical Details
Message-ID:
<271@hoqam.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!houxm!hoqam!vedmReferences:
<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!cbatt!ihnp4!houxm!hoqam!vedm From: vedm@hoqam.UUCP (BEATTIE) Newsgroups: net.lang.c Subject: Re: sizeof (int) - 1 Message-ID: <271@hoqam.UUCP> Date: Tue, 30-Sep-86 08:49:25 EDT Article-I.D.: hoqam.271 Posted: Tue Sep 30 08:49:25 1986 Date-Received: Wed, 1-Oct-86 05:15:42 EDT References: <102500008@uiucuxc> Organization: AT&T Bell Laboratories, Holmdel Lines: 20