Topic: Calling c++ from a c program


Author: rs@heike.informatik.uni-dortmund.de (Roland Schwan)
Date: 26 Jun 91 14:18:39 GMT
Raw View
Hello netters!

Is there any chance to call a C++- method from a c-program?

Such as :

...c-file:

main()
{....
..
something();
....
}

...c++-file:

....

void something();
{
 cout << "Output of c++ \n";
}

When I tried this, all I got was a core dumped.

Any ideas?

Roland.

____________________________________________________

Roland Schwan
rs@heike.informatik.uni-dortmund.de

It's better to burn out, than to fade away! (Kurgan)
____________________________________________________




Author: raeburn@athena.mit.edu (Ken Raeburn)
Date: 27 Jun 91 01:14:36 GMT
Raw View
In article <3575@laura.UUCP> rs@heike.informatik.uni-dortmund.de (Roland Schwan) writes:

   ...c-file:

   main()
   {....
   ..
   something();
   ....
   }

The problem here is that some C++ implementations (UNIX ones at least
-- I haven't used others, and you didn't say what you were using)
require that `main' be compiled as C++ code, in order for constructors
for static objects to be run.

If you can't move this `main' routine into a C++ file, rename it to
`main2' or something, and add a new `main' routine in a C++ file which
simply calls `main2'.