Question of casts, lvalues, and & operator
I've found that G++ 3.2 has a problem optimizing this code.
int func_b (void** ppv)
*ppv = (void*) 2;
char* test (void)
char* pa = NULL;
int main (int, char**)
char* p = NULL;
p = test ();
printf ("%p\n", p);
When compiling with -O0, everything is OK. -Os, on the other hand,
will optimize the return and always yield NULL.
I sent a preprocessed version of the errant file to gcc-bugs and was
told that my syntax is faulty and that the compiler will issue
Here's his comment:
(Your code should get a warning, or perhaps even a hard error -
you're applying the & operator to a cast to non-reference type, which
is not an lvalue, so it's invalid.)
Yet, -Wall does not make the compiler complain.
He says that the line ought to be
which does generate correct code. Still, it seems to me that either
the compiler ought to warn or error, *or* the original code ought to
So, is this simply an example of the compiler failing to warn?