I discovered few days ago Compound literals in the answer How do I use setsockopt(SO_REUSEADDR)?
So I tried to compile simple code :
#include <stdio.h>
int main()
{
int * ptr = &(int) {3};
printf("%d\n", *ptr);
return 0;
}
Using gcc 4.9.1, it build and works as expected, it print "3" and valgrind doesnot report memory corruption.
However using g++ 4.9.1, it does not build :
$ g++ main.c
main.c: In function ‘int main()’:
main.c:4:23: error: taking address of temporary [-fpermissive]
int * ptr = &(int) {3};
^
Is there is a way (like an g++ option) to support Compound literal ?