473,761 Members | 7,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does the expression "sizeof(int )*p" mean?

Does it mean "(sizeof(in t))* (p)" or "sizeof( (int)(*p) )" ?

According to my analysis, operator sizeof, (type) and * have the same
precedence, and they combine from right to left. Then this expression should
equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why?

Can anyone help me? Thanks.

Best regards.
Roy


Jul 19 '05 #1
70 8898
"Roy Yao" <fl***@263.ne t> wrote in message news:<bk******* ****@mail.cn99. com>...
Does it mean "(sizeof(in t))* (p)" or "sizeof( (int)(*p) )" ?

According to my analysis, operator sizeof, (type) and * have the same
precedence, and they combine from right to left. Then this expression should
equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why?

Can anyone help me? Thanks.

Best regards.
Roy



Hey,
Both "(sizeof(in t))* (p)" or "sizeof( (int)(*p) )" are not same.
"(sizeof(in t))* (p)" means you are multiplying sizeof(int), i.e. 2
(bytes), with the value of "p". Whereas "sizeof( (int)(*p) )" means,
First you are getting the value of at the adderess p (because *p gives
the value of another variable), then you are converting the returned
value into interger format and finally you are detecting the size of
that result. If you have any doubts contact at my ID
ke***********@y ahoo.co.in.

Be Cool,
Y. Keerthi
Sagar & Ashok.
Jul 19 '05 #2
Hello Keerthi,

Thanks for your enthusiasm.

My email to you was rejected by your mail server, so I reply you here.

In this expression, what confused me is how the compilers (or ANSI C)
determine the combination of operator sizeof, (type) and *.

In my opion it should equal to expression "sizeof( (int)(*p) )". The
reason is that operator sizeof, (type) and * have the same
precedence, and they combine from right to left. But the compilers prefer
"(sizeof(in t))* (p)".

Now can you give me a convictive explain from the precedence and
combination order of operator ?

Thanks again.

Best regards,
Roy Yao
Jul 19 '05 #3
On Tue, 16 Sep 2003 08:44:02 +0800, Roy Yao wrote:
Hello Keerthi,

Thanks for your enthusiasm.

My email to you was rejected by your mail server, so I reply you here.

In this expression, what confused me is how the compilers (or ANSI C)
determine the combination of operator sizeof, (type) and *.

In my opion it should equal to expression "sizeof( (int)(*p) )". The
reason is that operator sizeof, (type) and * have the same
precedence, and they combine from right to left. But the compilers prefer
"(sizeof(in t))* (p)".

Now can you give me a convictive explain from the precedence and
combination order of operator ?


I told you in my other post, that's NOT the (type) operator! (type) is the
/operand/ of sizeof.

Josh
Jul 19 '05 #4
On Mon, 15 Sep 2003 22:00:09 -0400, Josh Sebastian <cu****@cox.net >
wrote:

: On Tue, 16 Sep 2003 08:44:02 +0800, Roy Yao wrote:
:
: > Hello Keerthi,
: >
: > Thanks for your enthusiasm.
: >
: > My email to you was rejected by your mail server, so I reply you here.

You(Roy) are supposed to reply here.

: > In this expression, what confused me is how the compilers (or ANSI C)
: > determine the combination of operator sizeof, (type) and *.
: >
: > In my opion it should equal to expression "sizeof( (int)(*p) )". The
: > reason is that operator sizeof, (type) and * have the same
: > precedence, and they combine from right to left. But the compilers prefer
: > "(sizeof(in t))* (p)".
: >
: > Now can you give me a convictive explain from the precedence and
: > combination order of operator ?
:
: I told you in my other post, that's NOT the (type) operator! (type) is the
: /operand/ of sizeof.

You are right, but he wants to know why. :)

Some relevent production rules:

unary-expression:
postfix-expression
++ cast-expression
-- cast-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-id )
new-expression
delete-expression

unary-operator: one of
* & + - ! ~

The expression in question:

sizeof (int) * p

'(int) * p' isn't a unary-expression, because it is not starting
with ++, --, *, &, +, -, !, ~, sizeof, new, or delete, and it is
not a postfix-expression (believe me!). So a compiler can't parse
the expression in question as 'sizeof unary-expression'.
Regards,
tx
Jul 19 '05 #5

"Roy Yao" <fl***@263.ne t> wrote in message
news:bk******** ***@mail.cn99.c om...
Hello Keerthi,

Thanks for your enthusiasm.

My email to you was rejected by your mail server, so I reply you here.

In this expression, what confused me is how the compilers (or ANSI C)
determine the combination of operator sizeof, (type) and *.

In my opion it should equal to expression "sizeof( (int)(*p) )". The
reason is that operator sizeof, (type) and * have the same
precedence, and they combine from right to left. But the compilers prefer
"(sizeof(in t))* (p)".

Now can you give me a convictive explain from the precedence and
combination order of operator ?


sizeof is a function, and the parameter it takes is whatever is inside the
parens. If you wrote
sizeof((int)*p) , you'd evaluate the expression inside the outer parens
first. You cast whatever
*p is to an int, then take the size of that. Same as sizeof(int). But what
you wrote in your subject
is not exactly the same as either of the 2 options in your text message.
Jul 19 '05 #6
jeffc wrote:
sizeof is a function,
No, it's not. It is an operator.
and the parameter it takes is whatever is inside the
parens. If you wrote
sizeof((int)*p) , you'd evaluate the expression inside the outer parens
first.


No, sizeof's operand is not evaluated.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #7

"jeffc" <no****@nowhere .com> wrote in message news:3f******** @news1.prserv.n et...
sizeof is a function,
sizeof is not a function. It's an operator.
and the parameter it takes is whatever is inside the
parens.
Sorry untrue. The parens aren't strictly requird. The grammar of sizeof
is:

sizeof unary-expression // note no parens here.
swizeof ( type-id )
you'd evaluate the expression inside the outer parens
first.


Parens have no bearing on order of evaulation in C++.
Jul 19 '05 #8

"jeffc" <no****@nowhere .com> wrote in message
news:3f******** @news1.prserv.n et...

"Roy Yao" <fl***@263.ne t> wrote in message
news:bk******** ***@mail.cn99.c om...
Hello Keerthi,

Thanks for your enthusiasm.

My email to you was rejected by your mail server, so I reply you here.

In this expression, what confused me is how the compilers (or ANSI C)
determine the combination of operator sizeof, (type) and *.

In my opion it should equal to expression "sizeof( (int)(*p) )". The
reason is that operator sizeof, (type) and * have the same
precedence, and they combine from right to left. But the compilers prefer "(sizeof(in t))* (p)".

Now can you give me a convictive explain from the precedence and
combination order of operator ?
sizeof is a function, and the parameter it takes is whatever is inside the
parens. If you wrote
sizeof((int)*p) , you'd evaluate the expression inside the outer parens
first. You cast whatever
*p is to an int, then take the size of that. Same as sizeof(int). But

what you wrote in your subject
is not exactly the same as either of the 2 options in your text message.


Additionally, his second option: (sizeof(int)*(p )) is exactly the same as
the one in his subject line.
DrX.
Jul 19 '05 #9

"jeffc" <no****@nowhere .com> wrote in message
news:3f******** @news1.prserv.n et...

sizeof is a function, and the parameter it takes is whatever is inside the
parens. If you wrote
sizeof((int)*p) , you'd evaluate the expression inside the outer parens
first. You cast whatever
*p is to an int, then take the size of that. Same as sizeof(int). But what you wrote in your subject
is not exactly the same as either of the 2 options in your text message.


No, sizeof is an operator. The paranteses are only required for uses with a
type expression. Any other use only need them because of precedence.
Examples are:

sizeof(int)
sizeof 12345
sizeof 'a'
sizeof (a + b)

DrX.
Jul 19 '05 #10

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

Similar topics

4
1689
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
5
3605
by: aarklon | last post by:
Hi all, why printf("....%d",sizeof((int)(double)(char) i)) always gives the size of int ??? is it because sizeof doesn't evaluate its operand....???
0
9336
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,...
0
10111
Oralloy
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...
1
9902
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
9765
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...
1
7327
isladogs
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...
0
6603
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
5215
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...
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
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.