This question is similar to, but more specific than, this other question:
using struct keyword in variable declaration in C++.
Consider the following program:
#include <stdio.h>
struct Foo {
int x;
int y;
};
Foo getFoo() {
Foo foo;
return foo;
}
int main(){
getFoo();
}
The above program compiles with g++
but not gcc
.
We can modify the program as follows to make it compile with both gcc
and g++
:
#include <stdio.h>
struct Foo {
int x;
int y;
};
struct Foo getFoo() {
struct Foo foo;
return foo;
}
int main(){
getFoo();
}
Is this use of the struct
keyword guaranteed by the standard to be well-defined in C++?