Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: sizeof(x)
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 13 Topic 25205 of 28006
Post > Topic >>

Re: sizeof(x)

by Harald van =?UTF-8?b?RMSzaw==?= <truedfx@[EMAIL PROTECTED] > Mar 30, 2008 at 10:13 PM

On Sun, 30 Mar 2008 23:07:05 +0300, Ioannis Vranos wrote:
> Harald van Dijk wrote:
>> On Sun, 30 Mar 2008 22:50:00 +0300, Ioannis Vranos wrote:
>>> In C99 it is mentioned:
>>>
>>> "The sizeof operator yields the size (in bytes) of its operand, which
>>> may be an expression or the parenthesized name of a type.".
>>>
>>> If I am not wrong, this implies that
>>>
>>> int x;
>>>
>>> size_t y= sizeof(x);
>>>
>>>
>>> is not valid.
>> 
>> You are; (x) is a perfectly valid expression, so there's no problem
>> taking the size of (x).
> 
> I first saw that only sizeof x is valid at the pdf hosted at
> http://cprog.tomsweb.net.

That doesn't say sizeof(x) is invalid any more than the standard does.

> Then I checked the C99 standard and it mentions what is shown above.
> Clearly C99 doesn't mention parenthesized expression.

Yes, it does. Look at the grammar.

unary-expression:
  sizeof unary-expression

unary-expression:
  postfix-expression

postfix-expression:
  primary-expression

primary-expression:
  ( expression )

A parenthesised expression is a primary-expression, which is a postfix-
expression, which is a unary-expression, which is a valid operand of 
sizeof.

The standard doesn't explicitly mention that parenthesised expressions 
are valid operands of +, -, *, /, ^, &, or pretty much any other 
operator. The grammar makes that clear already.
 




 13 Posts in Topic:
sizeof(x)
Ioannis Vranos <ivrano  2008-03-30 22:50:00 
Re: sizeof(x)
Harald van =?UTF-8?b?RMSz  2008-03-30 22:04:00 
Re: sizeof(x)
Ioannis Vranos <ivrano  2008-03-30 23:07:05 
Re: sizeof(x)
Ioannis Vranos <ivrano  2008-03-30 23:08:39 
Re: sizeof(x)
Ian Collins <ian-news@  2008-03-31 09:10:25 
Re: sizeof(x)
Ioannis Vranos <ivrano  2008-03-30 23:11:55 
Re: sizeof(x)
Eric Sosman <esosman@[  2008-03-30 17:21:19 
Re: sizeof(x)
Ioannis Vranos <ivrano  2008-03-31 00:22:19 
Re: sizeof(x)
Keith Thompson <kst-u@  2008-03-30 14:30:47 
Re: sizeof(x)
richard@[EMAIL PROTECTED]  2008-03-31 22:39:55 
Re: sizeof(x)
Kaz Kylheku <kkylheku@  2008-03-30 16:17:12 
Re: sizeof(x)
Harald van =?UTF-8?b?RMSz  2008-03-30 22:13:14 
Re: sizeof(x)
Harald van =?UTF-8?b?RMSz  2008-03-30 22:15:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 11:19:28 CST 2008.