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 36 2794
On Oct 6, 9:39 pm, Frederick Gotham <fgotha...@SPAM .comwrote:
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
"sizeof ((double)5)" works well.
Cong Wang wrote:
On Oct 6, 9:39 pm, Frederick Gotham <fgotha...@SPAM .comwrote:
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
"sizeof ((double)5)" works well.
Cong Wang posted:
"sizeof ((double)5)" works well.
Yes, I realise that. My question pertains to operator precedence and
associativity -- specifically, why:
sizeof(double)5
is interpretted by gcc as:
(sizeof(double) )5
rather than:
sizeof((double) 5)
--
Frederick Gotham
Frederick Gotham <fg*******@SPAM .comkirjoitti 06.10.2006:
sizeof has the same precedence as a cast
No it doesn't.
Has it got something to do with "globbing"?
Unlikely.
In article <M0************ *******@news.in digo.ie>,
Frederick Gotham <fg*******@SPAM .comwrote:
>sizeof has the same precedence as a cast
The standard does not describe C's syntax in terms of operator
precedence; that's just a handy way of summarizing some common cases.
The relevant part of the grammar is:
unary-expression:
[...]
unary-operator cast expression
sizeof unary-expression
sizeof ( type-name )
cast-expression:
unary-expression
( type-name ) cast expression
So in:
sizeof(double)5 ;
"(double)5" is not a unary expression, so only "sizeof ( type-name )"
is possible, and that of course doesn't work because of the "5"
afterwards.
-- Richard
On Oct 6, 9:39 pm, Frederick Gotham <fgotha...@SPAM .comwrote:
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;
}
The code: sizeof(double)5 ; in the example mean: sizeof(double) [X] 5;,
in the example the sequence [X] is none. It is trying to connect two
numeric expressions without operators. This is not correct. You may
mean some similar code like the following.
int main(void){
/*sizeof(double) 5;*/
sizeof(double) * 5;
sizeof((double) 5);
return 0;
}
On Oct 6, 9:39 am, Frederick Gotham <fgotha...@SPAM .comwrote:
sizeof has the same precedence as a cast
No, the sizeof operator has a higher precedence than the cast operator.
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;
}
As it shouldn't because it doesn't make any sense.
Has it got something to do with "globbing"?
I have no idea what you mean by "globbing" in this context, your
expression is evaluated as:
(sizeof(double) ) 5;
which is a syntax error and is why it doesn't compile.
Robert Gamble
Richard Tobin posted:
unary-expression:
[...]
unary-operator cast expression
sizeof unary-expression
sizeof ( type-name )
cast-expression:
unary-expression
( type-name ) cast expression
So in:
> sizeof(double)5 ;
"(double)5" is not a unary expression, so only "sizeof ( type-name )"
is possible, and that of course doesn't work because of the "5"
afterwards.
So is a unary expression something simple like a literal or the name of an
object? Does that mean that the following should be bogus:
int main(void)
{
sizeof(5+4);
return 0;
}
It compiles just fine with gcc.
--
Frederick Gotham
lovecreatesbea. ..@gmail.com posted:
The code: sizeof(double)5 ; in the example mean: sizeof(double) [X] 5;,
in the example the sequence [X] is none. It is trying to connect two
numeric expressions without operators. This is not correct. You may
mean some similar code like the following.
int main(void){
/*sizeof(double) 5;*/
sizeof(double) * 5;
sizeof((double) 5);
return 0;
}
No. As I've already mentioned, this entire thread is to do with operator
precedence and associativity.
--
Frederick Gotham This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 ; };
|
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
|
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
|
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
|
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
| |
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++;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |