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

J

jeffc

WW said:
Sure. They are not function calls. There are several reasons to it. One
of ehich Ron told.

Really? They're not function calls because the order in which they appear
does not necessarily match the order in which they're called? Is that what
you're saying the "proof" is that they're not functions?
Another (which leads to the same) is that contsructors
are not functions. They are *special* member functions, which special
semantics.

Ah, I see. They're not functions. They're *special* functions. Thanks for
clearing that up.
Yes. How does that support your theory of sizeof being a function from the
C++ language point of view?

It supports my view that my comments are relevant to the context of the OP's
original question. He wrote sizeof((int)*p). Now if context makes no
difference, then how about if you come up and explain to the class the
difference between these 4 expressions.
short s;
sizeof s*(double)s
sizeof (double)s*s
sizeof (s*(double)s)
sizeof ((double)s*s)
And please don't tell me they're the same.
 
W

WW

jeffc said:
It also says "a function declaration". What does that mean?

I am sorry? You do not know what a function declaration means? Oh boy.
And does that prove anything?

It only proves that operators are not functions.
You're being silly.

Really? Since when are you a mental health expert?
Operators take arguments.

Yeah. That makes them more functional than you are. Try to read the
exceprt from the standard again.
They act like functions.

No, they don't. One reason is because they are not functions. Take the
member access operator for example (the . operator). Does that act as a
function? Nope. Some (actually very very few) operators may *look* like a
function call in code in some of their allowed form(s). But just the same
way as yellow snow is not from tee with lemon, operators in C++ are not
functions. Overloaded operators are *implemented* as functions.
If the context of this discussion were different,
you'd be arguing the opposite side just as
vehemently.

Now you are a mind reader, too. Boy are you talented! How come I have
never heard about your achivements before?
You know exactly what I'm talking about, so you're just
being arbitrary.

Yes, I am being arbitrary. By the "absolute" meaning of the word
"arbitrary". How come? There is only one absolute which decides what is
what in C++. And that is the standard. And that clearly makes a
fundamental distinction between operators and functions. Therefore they are
not the same.
 
W

WW

jeffc said:
Really? They're not function calls because the order in which they
appear does not necessarily match the order in which they're called?

Amongst other things, yes.
Is that what you're saying the "proof" is that they're not functions?

What are they? The proof that constructors are not functions is in the
standard. Read it. They are special member functions. For one example how
special they are: they have no names. But again: read the standard.
Ah, I see. They're not functions. They're *special* functions.
Thanks for clearing that up.

No. They are *special* member functions. One of their specialty is that
they do not have a name. The have special semantics.
It supports my view that my comments are relevant to the context of
the OP's original question. He wrote sizeof((int)*p). Now if
context makes no difference, then how about if you come up and
explain to the class the difference between these 4 expressions.
short s;
sizeof s*(double)s
sizeof (double)s*s
sizeof (s*(double)s)
sizeof ((double)s*s)
And please don't tell me they're the same.

By meaning they are the same. All are takig the size of the type of the
expression (double)s*(double(s), which is sizeof(double).

I still see the above as an example against your idea of operators being
functions.
 
K

Kevin Goodsell

jeffc said:
Same thing.

Absolutely not. A few differences are that sizeof is never 'called' (it
is evaluated at compile time), and sizeof does not have an address. A
consequence of the first point is that the operand of 'sizeof' is not
evaluated:

int i = 0;
sizeof(++i);
assert(i == 0); // OK, i has not changed.
Of course they do.

No, they don't.
Compare:
1 + (2 * 3)
(1 + 2) * 3

This is an example of parens being used to change precedence. Precedence
and order of evaluation are not the same. Given

exp1 + exp2

the order that exp1 and exp2 are evaluated is not specified. Adding
parens does not change this:

(exp1 + exp2)
(exp1) + exp2
exp1 + (exp2)

None of these make the order of evaluation specified. Similarly, given a
statement that modifies a variable twice without an intervening sequence
point:

i = i++;

You cannot make the result of this well-defined by adding any number of
parens, because the order of evaluation of the assignment and the
increment is not specified and parens don't change it:

i = (i++); // still undefined

-Kevin
 
K

Kevin Goodsell

jeffc said:
It also says "a function declaration". What does that mean? And does that
prove anything? You're being silly. Operators take arguments. They act
like functions.

Please show me how to take the address of the sizeof function. I know
all functions have addresses, and thanks to you I now know that sizeof
is a function, therefore must have an address. Can you please show me
how to determine this address? Thank you.

-Kevin
 
W

WW

Kevin said:
Please show me how to take the address of the sizeof function. I know
all functions have addresses, and thanks to you I now know that sizeof
is a function, therefore must have an address. Can you please show me
how to determine this address? Thank you.

It is:

Dwight Look College of Engineering | Texas A&M University
301 Harvey R. Bright Bldg, College Station, TX 77843-3112

Do you also want a phone number? ;-)
 
K

Kevin Goodsell

Kevin said:
Please show me how to take the address of the sizeof function. I know
all functions have addresses, and thanks to you I now know that sizeof
is a function, therefore must have an address. Can you please show me
how to determine this address? Thank you.

Here's another revelation thanks to this new "operators are functions"
rule. The following is no longer undefined:

int i = 0;
i = i++;
assert(i == 0);
i = ++i;
assert(i == 1);

Since '=' is a function, there is a sequence point before it is called,
and the increment operation is finalized. Unfortunately, some compilers
still seem to give incorrect results for this. I guess they haven't
implemented "operators are functions" yet.

-Kevin
 
X

Xenos

jeffc said:
with

Makes no difference.

Makes all the difference in the world. The argument to sizeof is not
evaluated as would be for a function. saying "sizeof(++i)" does not change
the value of i. Futhermore, I don't know any function that can take a type
as an argument, as in sizeof(int). sizeof is a compiler constructor, it is
never executed by the runtime.

DrX.
 
R

Ron Natalie

jeffc said:
Operators are functions

No they are not. User overloaded operators are functions. Other than that
they do not have anything in common with functions and the rules of functions
do not apply to the ones that aren't implemented as functions.
different.
The syntax is not the same at all and the semantics are completely different.
 
J

jeffc

WW said:
I am sorry? You do not know what a function declaration means? Oh boy.

You do not know how to draw logical conclusions? Oh boy. Obviously I meant
"what does that mean with regard to your argument?" It called it a
"function declaration". That implies a "function". What you wrote supports
my argument, not yours.
It only proves that operators are not functions.

Try again.
 
J

jeffc

Kevin Goodsell said:
Please show me how to take the address of the sizeof function. I know
all functions have addresses, and thanks to you I now know that sizeof
is a function, therefore must have an address. Can you please show me
how to determine this address? Thank you.

Can't be done Kevin. As I've already said, my comments are to be taken in
context. You're just another pedant with too much time on your hands. Why
don't *you* explain why WW quoted text referring to "function declarations"
in the context of operators? I'm sure that will occupy you for quite
awhile.
 
A

Attila Feher

jeffc said:
You do not know how to draw logical conclusions? Oh boy. Obviously
I meant "what does that mean with regard to your argument?" It
called it a "function declaration". That implies a "function". What
you wrote supports my argument, not yours.

Thank you for the clarification. It means that operators are not functions,
but certain special function declarations are used to implement operators.

No need to. It is proven by several people, even known experts, all over
this thread. My goal is not to necessarily convince you, but to show to
those who are ready to think and read that operators are not functions.
 
A

Attila Feher

jeffc said:
Can't be done Kevin. As I've already said, my comments are to be
taken in context. You're just another pedant with too much time on
your hands. Why don't *you* explain why WW quoted text referring to
"function declarations" in the context of operators? I'm sure that
will occupy you for quite awhile.

Dear Clever Boy,

I did that because *you* were bringing up the term "Operator Functions". I
have shown you from the standard that the place defining what operator
functions are does nto say that operators are functions, but it says that
some special functions are used to implement user defined operators. You
are the one taking the quotes out of context.
 
J

jeffc

WW said:
Amongst other things, yes.

Then I'm sure you'd agree that f(), g() and h() are not functions?

int f(){return 2;}
int g(){return 3;}
int h(){return 4;}

int i = f() * (g() + h());

What is the result? If the functions are called in the order they appear,
then the result will be 10. Is that the result? Since the order the
functions appear is not the order in which they're called, then by your
definition they are not functions, right?
By meaning they are the same. All are takig the size of the type of the
expression (double)s*(double(s), which is sizeof(double).

Ho ho! Nice try. Try using a compiler and running some code for a change.
You have no idea what you're talking about.
 
J

jeffc

Absolutely not. A few differences are that sizeof is never 'called' (it
is evaluated at compile time), and sizeof does not have an address. A
consequence of the first point is that the operand of 'sizeof' is not
evaluated:

int i = 0;
sizeof(++i);
assert(i == 0); // OK, i has not changed.

I meant for purposes of this discussion, but... I see your point. Point
conceded.
No, they don't.


This is an example of parens being used to change precedence. Precedence
and order of evaluation are not the same.

But order of evaluation is changed, one way or another.
 
A

Attila Feher

jeffc said:
Then I'm sure you'd agree that f(), g() and h() are not functions?

int f(){return 2;}
int g(){return 3;}
int h(){return 4;}

int i = f() * (g() + h());

You have to really learn what expressions are. Here you have several of
them.
Ho ho! Nice try. Try using a compiler and running some code for a
change. You have no idea what you're talking about.

I do. I just want to know if you do, too. But it seems there is no way to
make you show up any C++ knowledge.

BTW you above game with operator precedence is nice as a trick. Also nice
because it nicely supports the fact that operators are not functions. Since
functions have no precedence. The function call operator - however - does
 
J

jeffc

Attila Feher said:
I do. I just want to know if you do, too. But it seems there is no way to
make you show up any C++ knowledge.

In other words, those are not all sizeof(double) correct? You didn't try
it, did you?
BTW you above game with operator precedence is nice as a trick.

The point being that you were being pedantic. You said that if the order
the calls appear does not match the order in which they're called, then the
things being called aren't functions. This "proves" that constructors
aren't functions, according to you, because the order in which they appear
on the initializer list doesn't necessarily match the order in which they're
called. This has nothing to do with any definition of functions.
 
J

jeffc

Ron Natalie said:
No they are not. User overloaded operators are functions. Other than that
they do not have anything in common with functions and the rules of functions
do not apply to the ones that aren't implemented as functions.

They absolutely do have things in common with functions, and it's ridiculous
to say otherwise. In fact, if I show you a statement with an operator in
it, you wouldn't even be able to tell me if it was a function or not.

a = b + c;

In fact, since I've already conceded the point to Kevin, it would be just as
logical to argue that sizeof is not even an operator, since it doesn't
follow the exact same rules as other operators. It doesn't necessarily mean
it's not an operator, and it doesn't necessarily mean operators aren't
functions, depending on the context of the discussion. Some of you guys
just love to try to read the letter of the law rather than the intent.

By the way, how do *you* explain the differences between these 4?
short s;
sizeof s*(double)s
sizeof (double)s*s
sizeof (s*(double)s)
sizeof ((double)s*s)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top