From: Timothy Madden on
Hello

Is this legal C++:

struct Coord
{
int a;
float f;
}
GetLastCoord()
{
Coord c;

c.a = 0;
c.f = 2.7f;

return c;
}

?

I could not find the paragraf for that in the standard.
gcc gives an error and Visual Studio compiles the code

Thank you,
Timothy Madden

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 21 Jun., 15:07, Timothy Madden <terminato...(a)gmail.com> wrote:
> Hello
>
> Is this legal C++:
>
> struct Coord
> {
> int a;
> float f;
> }
> GetLastCoord()
> {
> Coord c;
>
> c.a = 0;
> c.f = 2.7f;
>
> return c;
> }
>
> ?

No.

> I could not find the paragraf for that in the standard.
> gcc gives an error and Visual Studio compiles the code

You can find it in 8.3.5/6 of the C++03 standard:

"[..] Types shall not be defined in return or parameter types. [..]"

This was an intentional change versus C and is also mentioned
in the list of those change in the compatibility annex C.1.6
[diff.decl] 8.3.5.

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]