LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] gcc optimisation weirdness?

[ILUG] gcc optimisation weirdness?

Kenn Humborg kenn at bluetree.ie
Thu May 11 11:31:41 IST 2000


> 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







More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell