Explicit type conversion.

L

LR

I've gotten an error message from this snippet:

void f() {
unsigned int x = unsigned int (5);
}


N2857, 5.2.3 Explicit type conversion (functional notation), seems to
imply that this is valid code, but perhaps I am misreading it.

Is this a compiler bug?

TIA.
LR
 
B

Bo Persson

LR said:
I've gotten an error message from this snippet:

void f() {
unsigned int x = unsigned int (5);
}


N2857, 5.2.3 Explicit type conversion (functional notation), seems
to imply that this is valid code, but perhaps I am misreading it.

Is this a compiler bug?

No.

You just cannot use functional notation with types consisting of
several keywords. Try unsigned(5), or perhaps 5u.



Bo Persson
 
C

ctrucza

I've gotten an error message from this snippet:
void f() {
    unsigned int x = unsigned int (5);

}

Posting the error message would be very helpful. So would be the OS/
compiler you are using.
 
J

James Kanze

I've gotten an error message from this snippet:
void f() {
unsigned int x = unsigned int (5);
}
N2857, 5.2.3 Explicit type conversion (functional notation),
seems to imply that this is valid code, but perhaps I am
misreading it.

You're misreading it, but I don't really see how. The grammar
doesn't have any construct which will parse the above, so it
isn't legal. The syntax of an explicit type conversion
(functional notation) is:

simple-type-specifier ( expression-list[opt] )
typename-specifier ( expression-list[opt] )

A simple-type-specifier is either a single keyword which names a
type (e.g. int or unsigned), a class, enum or typedef name, or a
name declared by a typedef. A typename-specifier is something
along the lines of "typename ...", where the ... must be a
qualified id.

Compare this with explicit type conversion (cast notation),
where the syntax is:
( type-id ) cast-expression
This allows an arbitrarily complicated type specifier (e.g.
unsigned int, char const*, int (C::* (*)())(), etc.---not that
I'd recommend things like that last one in production code).
 

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,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top