sizeof('x') in C and in C++

D

Dik T. Winter

> 3. if its a variadic function, a four-byte int, which contains the value of
> char x, is passed to f( ) unix/intel platform).
>
> right?

Not entirely. In the context of:

char c;
void f(char p, ...);

in the call f(c, c) the first argument is passed as a char, the
second as an int.
 
J

Jack Klein

I'd like to amend that even the brackets are optional. There are two ways
to invoke sizeof, one taking a reference and the other taking a type:

sizeof some_object;// no brackets necessary
sizeof (float);// brackets necessary

Not quite accurate. The first one should be:

sizeof some_expression;

....as, for example, sizeof 'a'. No parentheses required. And no
object required, either.
 
D

Denis Kasak

jimjim said:
I posted a question some time ago to this group about variadic functions and
I learned about integer promotions...so allow me to fire another question:

1. When there is a function prototype, e.g. void f(char x), is the char
passed to the function promoted to an int?

No, it is passed as a char.
2. In a variadic function, a char passed to a function is definatelly
promoted to an int, right?

Not definitely. Char parameters that are explicitly designated in the
declaration are passed as char. If the variadic part of the parameter
list contains a char, then it is promoted to int.
3. Is there any difference between invoking f( ) as f( x ) and f('x')?

Yes, it is completely different. The first passes the value of the
variable x and the second the ordinal representation of the character 'x'.
4. Unfortunatelly, I cannot find sizeof( )'s prototype :-( .

I would be surprised if you did; sizeof is an operator, rather than a
function.

-- Denis
 
P

Peter Nilsson

Emmanuel said:
jimjim wrote on 13/09/05 :

What the hell is C++ ?

What planet are you living on?
We are on clc.

Is that anywhere near Earth? ;)

The OP wasn't asking about the new operator, they were trying to
explain
their reasoning for thinking that sizeof() needs a prototype.

If someone learning French comes up to you and explains why they
misunderstood a 'faux amis', would you tell them to piss off because
you don't speak English, or would you politely explain that, despite
the identical spelling, the languages are distinct and the same word
should be treated in context?
 
S

Simon Biber

jimjim said:
Would you disagree with this opinion, which was posted in a past thread
discussing the issue in question?

"More specifically the integral promotions. In K&R C it was virtually (?)
impossible to use a character value without it being promoted to int first,
so making character constant int in the first place eliminated that step.
There were and still are multi character constants such as 'abcd' or however
many will fit in an int."

This opinion seems accurate to me.
Moreover, should integral read integer?

The word "integral" has many meanings, one of which is:
"Expressed or expressible as or in terms of integers."
Essentially the above quote is using "integral" as an adjectival form of
the noun "integer".
 

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

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top