🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3723

Re: 'sizeof e' vs. 'sizeof (T)' (was: Re: Parenthesis with return ?)

#3723
From: Dan Pop
Date: Mon, 14 Aug 1995 16:16
36 lines
1883 bytes
In <40nqhd$1rs4@usenetp1.news.prodigy.com> NGMV85A@prodigy.com (Paul Long) writes:

>clive@stdc.demon.co.uk (Clive D.W. Feather) wrote:
>>
>>In article <3415076830.8283127@ortel.org>,
>>Paul Long <Paul_Long@ortel.org> wrote:
>>> If [...] the following would all yield 1:
>>>   sizeof(char)
>>>   sizeof(int)
>>>   sizeof c
>>>   sizeof c + 1
>>
>>The last of these can never be 1 (assuming it occurs in a strictly
>>conforming program).
>
>Sure it would.  The usual arithmetic promotions would cause "c" to be 
>converted to int as part of the integral promotions. At that point, both 
>sides would be type, int, and the type of the expression would therefore 
>also be type int. If an int is 16 bits long and a "byte," as defined by 
>the Standard, is 16 bits long (CHAR_BIT is 16), "sizeof c + 1" would 
>yield 1 because it has the value of the number of bytes in the type of 
>the expression, which in this case would be 1 "byte." Why do you think 
>"sizeof c + 1" can never be 1 in a conforming program?

Because the sizeof operator has a higher precedence than the binary +
operator :-)

I hope that your compilers parse that expression better than you did
yourself :-)

Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@mail.cern.ch 
Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID: <danpop.808417015@rscernix>
Path: arc1-ca.pugleaf.net!CERN.ch!rscernix!danpop
References: <3415076830.8283127@ortel.org> <dd9uho.ajm@stdc.demon.co.uk> <40nqhd$1rs4@usenetp1.news.prodigy.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!CERN.ch!rscernix!danpop
From: Dan.Pop@mail.cern.ch (Dan Pop)
Subject: Re: 'sizeof e' vs. 'sizeof (T)' (was: Re: Parenthesis with return ?)
X-Nntp-Posting-Host: ues5.cern.ch
Message-ID: <danpop.808417015@rscernix>
Sender: news@news.cern.ch (USENET News System)
Organization: CERN European Lab for Particle Physics
X-Newsreader: NN version 6.5.0 #9 (NOV)
References: <3415076830.8283127@ortel.org> <dd9uho.ajm@stdc.demon.co.uk> <40nqhd$1rs4@usenetp1.news.prodigy.com>
Date: Mon, 14 Aug 1995 16:16:55 GMT