default expression type

J

j0mbolar

does the standard guarantee that the type of an expression
is implicitly void as it does for functions?

for example:

int i = 0xff;

i;

does the type implicitly have void
since it isn't used for anything.
 
T

Thomas Matthews

j0mbolar said:
does the standard guarantee that the type of an expression
is implicitly void as it does for functions?

for example:

int i = 0xff;

i;

does the type implicitly have void
since it isn't used for anything.

Expressions have a type and a value.
In the statement:
i;
the type is "int" and its value is 0xFF. There does not have
to be any conversion to "void".

The compiler is free to optimize expressions and statements.
The expression above does not change any variables or memory
locations, so a good compiler will remove it from the code.

In the statement:
i = i + 5;
it still has type "int", but the value will be the result
of "i". The compiler does not convert its type, nor does
it need to. The compiler usually does not remove this
kind of statement.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

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
474,144
Messages
2,570,823
Members
47,369
Latest member
FTMZ

Latest Threads

Top