POV-Ray : Newsgroups : povray.programming : mixing POV code with C++ : Re: mixing POV code with C++ Server Time
29 Jul 2024 00:37:59 EDT (-0400)
  Re: mixing POV code with C++  
From: Jon A  Cruz
Date: 12 Feb 1999 01:39:30
Message: <36C3CD62.D5AEBC35@geocities.com>
Daniel Fenner wrote:

> Hi everybody !
>
> First of all : Thanks for the quick response !
>
> some more questions/remarks concerning POV and C++
>
> 1)  I guess 'extern "C" {...}' is used to include C headers into C++
> files
>     (correct me if I am wrong)
>     What I need is the opposite : including a C++ header into a C file.
>
> 2)  As a work-around I compiled the hole source code as C++. (the option
>     for VC5.0 is /TP) I'm not completly happy with this. A lot of things
>     had to be changed (prototypes and typecasts mainly) Furthermore the
>     linker now produces some unresolved references I can not explain.
>     I used /FORCE and had luck :->.
>
>     Does anyone know a 'nicer' way to solve this problem ?

Yes.
Valid C code is Valid C++ code.
'extern "C"' will prevent the name mangling.

Therefore, write the accessing of your C++ stuffs in a standard C way, plus
use the extern "C" around its definitions in your header files that are to
be included in the plain C code.

Of course, it is possible that a slight redesign in your code may be needed,
as C has no clue as to how to handle C++ specifics. That is to say, you
might need to create some kind of C compatible wrapper around your C++
objects, depending on how the latter are structured and used.

(I think this is just an elaboration on what Nigel posted earlier)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.