returning lvalue in C vs C++



Can anyone explain this:

struct thing
{
int x;
};

struct thing f(void)
{
struct thing ret = {100};
return ret;
}

int g(void)
{
return 10;
}

int main(void)
{
#if 0
g() = 4; /* "invalid lvalue" in C and C++ */
#endif
f().x = 200; /* "invalid lvalue" in C, but not in C++ apparently */

return 0;
}

$ gcc -x c++ main.c

no problems in C++, but

$ gcc -x c main.c

main.c: In function â??mainâ??:
main.c:17: error: invalid lvalue

I'm using gcc version 4.0.2 20050901.
.



Relevant Pages