"Jason luo" <ka***@eastnet.cn> wrote in message
news:8f**************************@posting.google.c om...
Hi all,
In c99-standard page 52,there is a sentence about void,as
below:
If an expression of any other type is evaluated as a void
expression, its value or designator is discarded.
I don't know how to understand it, How to evaluate the
expression as a void expression? explicit conversion the expression? but, befor
the sentence ,"implicit or explicit conversions (except to void)
shall not be applied to such an expression. " was mentioned.
thanks .
This is the way I read that part:
It starts off by talking about expressions that are of type void.
For instance, an expression that calls a void function would be a
void expression. If foo(k) is a void function, it's saying that
you can't do something like:
k = foo(k); (implicit conversion)
k = (int) foo(k); (explicit conversion)
But you can call:
(void) foo(k);
all day because you are allowed to cast a void expression to
void.
Nor could you do something like:
k = (int) ( (void) i++ );
Since you took an expression having a type and cast it to void.
It is now a void expression and you can't get at the value again
by doing a subsequent cast on it. As soon as it because a void
expression, the value became indeterminate and/or nonexistent.
You use void expressions because you want the side effect. The
only reason I can think of to cast an expression that has a type
to void is to perhaps suppress a compiler warning about unused
code or code having no effect or something like that. With the
operators that produce side effects I don't think you would get
such a warning - the compiler knows about the side effects of
those operators. I don't know if you it might be useful when
working with volatile variables.