On Tue, Oct 18, 2011, Oleg Goldshmidt wrote about "Re: Newer gcc swallow 
version control keywords":
> It was about C++. C and C++ compilers behave the same.

I was very surprised to discover that this is indeed the case. I think this
is a BUG. For example, consider this C++ program:

        #include <cstdio>
        class Ident {
        public:
                Ident(const char *ident){
                        // This constructor prints a message!
                        printf("yo\n");
                }
        };

        static Ident id("$Id: hello $");

        main(){
                printf("hello\n");
        }


If you compile it with g++ (without optimization), the object id gets
instanciated, and when you run the program you see the message "yo" first,
before "hello". But, if you compile it with g++ -O2, id gets optimized out
and its constructor never runs - and you never see the "yo" message.

So basically, compiling with -O2 changes the *behavior*, not just the
*performance*, of the code. I don't know how this cannot be called a bug?

But unfortunately, whether this is to be called a "bug" doesn't really
help you :(

-- 
Nadav Har'El                        |                   Tuesday, Oct 18 2011, 
n...@math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |This '|' is not a pipe.
http://nadav.harel.org.il           |

_______________________________________________
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il

Reply via email to