473,725 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Precedence of sizeof


sizeof has the same precedence as a cast, and they both bind from right to
left. The following won't compile for me with gcc:

int main(void)
{
sizeof(double)5 ;

return 0;
}

Has it got something to do with "globbing"?

--

Frederick Gotham
Oct 6 '06
36 2801
In article <oE************ *******@news.in digo.ieFrederic k Gotham <fg*******@SPAM .comwrites:
Richard Tobin posted:
unary-expression:
[...]
unary-operator cast expression
sizeof unary-expression
sizeof ( type-name )
....
So is a unary expression something simple like a literal or the name of an
object?
Richard skipped something. In addition to what he mentioned, it can
also be a "postfix-expression", and going further down the syntax we find that
(1) a postfix-expression can be a "primary-expression",
(2) a primary-expression can be:
identifier
constant
string-literal
( expression )
int main(void)
{
sizeof(5+4);
return 0;
}

It compiles just fine with gcc.
It should.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Oct 6 '06 #31
Frederick Gotham <fg*******@SPAM .comkirjoitti 06.10.2006:
Shouldn't an operator table clarify this though, indicating what's evaluated
in what order?
Operator precedence does not specify evaluation order; it is only used
to disambiguate ambiguous expressions. (Of course, in standard C, there
are no ambiguous expressions:)

Oct 7 '06 #32
sj*******@yahoo .com posted:
This post might be enlightening:
http://groups.google.com/group/comp....ec23?dmode=sou
rce

An absolute masterpiece of a post! I quite like:

| This, incidentally, is also why parentheses are
| not required around "b = c" in:
|
| result = (a ? b = c : d);
Still though, the following expression:

sizeof(double)-5

has an ambiguous parse, and so operator precedence should come into play --
which would lead me to believe that there is a cast involved.

--

Frederick Gotham
Oct 7 '06 #33
In article <qM************ *******@news.in digo.ie>,
Frederick Gotham <fg*******@SPAM .comwrote:
>Still though, the following expression:

sizeof(double)-5

has an ambiguous parse
It does not have an ambiguous parse according to the grammar in the
standard, because (double)-5 is not a unary expression and therefore
cannot be the argument to the argument to the sizeof operator.

-- Richard
Oct 7 '06 #34
Frederick Gotham wrote:
Fred Kleinschmidt posted:
Consider this:
sizeof(double)-5

There is a syntactic ambiguity in this type of expression. It could be
interpreted as three unary operators: negation, the cast (double)
and 'sizeof', successively applied to the value 5:
sizeof( (double)(-5) )
or it could be interpreted as a binaary subtraction whose
operands are sizeof(double) and 5:
(sizeof (double)) - 5

Shouldn't an operator table clarify this though, indicating what's evaluated
in what order?
Maybe you could address your concerns to whoever wrote
this "operator table" that you keep going on about.

The C standard does not define an "operator table" or "precedence ".

Oct 9 '06 #35
Frederick Gotham wrote:
Chris Dollin posted:
>Since the text doesn't parse, you can't say "5 is the operand of the cast"
or "The result of the cast is the operand of sizeof" and be talking
about C grammar.

Who knows if it doesn't parse?
Someone who reads the C grammar.
All I said was that gcc didn't compile it. gcc isn't C.
Even if gcc accepted the expression "batman @prescribes valium"
and compiled code to teleport tribbles to Gotham city, it wouldn't
cause the C grammar to suddenly accept as an expression the text
you've been quoting.

--
Chris "falling further in" Dollin
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/

Oct 9 '06 #36

Robert Gamble ha scritto:
>You do realize that
it is the Standard that dictates the precedence of operators, not
whatever table you are looking at don't you?
I read it, simply, from K&R and other C/C++ books

Oct 9 '06 #37

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
2691
by: Jeff Relf | last post by:
Hi All, I plan on using the following C++ code to create nodes with unlimited children: // I would like to declare NodeT like this, // but it won't compile because Lnk_T is not defined yet. struct NodeT { Lnk_T Lnk ; };
11
1553
by: Rupesh | last post by:
Hello all, See the code .... int i=-3,j=2,k=0,m; m=++i;&&++j||++k; printf ("%d %d %d %d",i,j,k,m); I executed this code on gcc. the o/p i had got is:- -2 3 0 1
7
1787
by: lovecreatesbea... | last post by:
c-faq, 4.3: The postfix ++ and -- operators essentially have higher precedence than the prefix unary operators. BSD Manual, OPERATOR(7): Operator Associativity -------- ------------- ! ~ ++ -- - (type) * & sizeof right to left Is there a complete table on operators, their precedence and
9
3746
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
7
1956
by: linq936 | last post by:
Hi, I am puzzled on this C puzzle: How to interpret this C statement: sizeof (int) * p Is that the size of integer type multiplies p or the size of whatever p points to in integer type? I think it should be the latter because there are 4 parser tokens here, sizeof, int, * and p, the first and the second are of same precedence which are higher than the third and all three operators are
32
3314
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x += i + j + k++;
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.