default expression type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • j0mbolar

    #1

    default expression type

    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.
  • Thomas Matthews

    #2
    Re: default expression type

    j0mbolar wrote:[color=blue]
    > 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.[/color]

    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:

    C++ Faq: http://www.parashift.com/c++-faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.l earn.c-c++ faq:

    Other sites:
    http://www.josuttis.com -- C++ STL Library book

    Comment

    Working...