pkenny@ADS.COM (Patrick Kenny) (05/03/90)
This has probabaly already been talked about before but.. I need to call C from C++ and C++ from C on a Sun Sparcstation. I wanted to know if anybody else out there can share their experiences as to how I can go about doing this. I know it can be done, by linking or compiling the C under C++, which may be a problem since the C routines are long and not entirely mine. I would prefer to keep the C and C++ seperate. On a second note, has anybody tried to make Interviews calls from C and vice versa. Any help would be thankful. -e-mail or post. -- ___________________________________________________ Patrick Kenny pkenny@saturn.ads.com | I Didn't Say it Advanced Decision Systems 1500 Plymouth Street | I Just Thought it. Mountain View, CA 94043 | My Computer Said it.
normanb@pinhead.citi.umich.edu (David R. Richardson) (03/25/91)
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