This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Mysterious C++


I had the idea of accessing C++ namespaces in a C program to make a complicated version of Hello World. I wrote a function "ns" to access the functions in a greeting namespace. The greeting namespace was

namespace greeting {
        char *greeting;
        void print(void), setstr(char *);
}

I wrote a C program to use the C++ program, compiled it with g++ cpp.c++ -x c c.c -g, and it didn't work. But when I added -O3 to the command line, it printed "Hello World". Bringing it down to -O still made it say Hello World, but turning off optimization stopped it. Very misterious. The sources are attached. The C file is c.c, the C++ file cpp.c++. I am using GCC 3.4.3.

Samuel Lauber
-- 
_____________________________________________________________
Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.

Powered by Outblaze

Attachment: c.c
Description: Binary data

Attachment: cpp.c++
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]