BCC wrote:
Can someone please explain this to me... if I have:
int x = 10;
I can do:
int* p_x = &x;
Compiles okay.
If I have a function though:
int ReturnInt() { return x; }
// Where x = 10;
and then do:
int* p_x = &ReturnInt();
I get a compiler error "C2102 '&' requires l-value".
I had thought that these should be the same. Clearly they are not, but Im
not sure why.
You're taking the address of a return value ?
Take this for example:
int * p = &(5+5);
In this case, 10 is not stored in memory, it's the result of an
expression and never is stored in the address space of the program so
you can't take the address of it. Also the return value from a function
is also not allways addressible as a pointer.
Anyhow, the issue really is that the DEFINITION OF THE LANGUAGE does not
permit you to take the address of a non "l-value" which is defined in
the language.
An l-value (left hand side value) is an expression that refers to an
object (or pod).