Mysterious C++

Sam Lauber sam124@operamail.com
Sun Dec 12 03:59:00 GMT 2004


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c.c
Type: application/octet-stream
Size: 107 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20041212/d638890f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpp.c++
Type: application/octet-stream
Size: 403 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20041212/d638890f/attachment-0001.obj>


More information about the Gcc mailing list