Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!umich!terminator!pinhead.citi.umich.edu!normanb From: normanb@pinhead.citi.umich.edu (David R. Richardson) Subject: C and C++ Message-ID: <1991Mar24.224946.2016@terminator.cc.umich.edu> Followup-To: normanb@ifs.umich.edu Sender: usenet@terminator.cc.umich.edu (usenet news) Reply-To: normanb@ifs.umich.edu Organization: IFS Project, University of Michigan Date: Sun, 24 Mar 91 22:49:46 GMT I am having difficulty with combining C and C++ modules into one executable. My project consists of a set of X Windows routines written in C and a set of logic routines written in C++. The X Windows code must call two C++ routines -- GameInit to initialize the simulator and GameTimer which processes one tick of the game clock. These are simple wrapper routines which do nothing more than call the appropriate C++ code. They are defined as extern "C". I am using ATT C++ 2.1 on a Sun Sparcstation 1+. Everything compiles and links just fine, but segmentation faults shortly into the run. I believe the problem occurs the first time a C++ io operation is called. I am using a simple piece of C code for a test -- all it does is invoke GameInit followed by GameTimer. An adb backtrace looks like: SIGSEGV 11: segmentation violation stopped at ___ls__7ostreamFPCc+0xc: ldsh [%l6 + 0x30], %l6 $c ___ls__7ostreamFPCc(0xc738,0xc148,0x0,0x0,0x0,0x0) + c _debugdump__4GameFv(0xe888,0x2,0xe908,0xe918,0x4,0x0) + 1c ___ct__4GameFiN71Ul(0xe888,0x1,0x2,0x3,0xe918,0xe8c8) + 1f8 _GameInit(0x1,0x2,0x3,0x4,0x5,0x2) + 5c _main(0x1,0xf7fffb24,0xf7fffb2c,0xc000,0x0,0x0) + 3c Where the first instruction in debugdump is: cout << " A New Game context\n" ; As I understand it, cfront causes the normal main() of a program to first call a special C++ _main() to do some initialization. It would appear that because main() is in code compiled by the C compiler, that _main () routine is never called and therefore the initialization is never performed. Is that true, and if so, what can I do about it? Please respond via mail, and I will post a summary. Thanks, david