> I'd be very interested if anyone could test the following code
> for me using gcc.
> // ===================================
> // AFAIK this shouldn't compile but VC++ thinks this
> // is just peachy.
>> struct PreludeToFailure(
> PreludeToFailure( int stuff ) : _internalStuff( stuff ) { }
>> int _internalStuff;
> }
>> main ()
> {
>> // do some stuff here
> // ...
> return 0;
>> }
>> // ===================================
>> This compiles under VC++ event with the strict ANSI compliance
> turned on ( -Za option for the MSVC compiler )
> despite ANSI C requiring an int return type from main.
> The program crashes - no shit - but still compiles as
> the struct takes an int in the constructor.
Defining types in the return value of a function is forbidden
by the C++ standard. This months Windows Developers Journal
covers exactly this issue in its Bug++ Of The Month column.
There are a couple of rules being broken, so the compiler
should complain:
o main() not returning int.
o main() not taking (int, char **)
o type defined in function return type specifier
I haven't tried your snippet with GCC, but I'd bet that it will
complain. If you try to do this in C under GCC:
int func(struct unknown *p);
GCC says that the scope of struct unknown is limited to the
argument list of func(). So they probably have checks for scopes
that are limited because the type is only defined as a return value.
Later,
Kenn
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!