POV-Ray : Newsgroups : povray.programming : mixing POV code with C++ Server Time
29 Jul 2024 02:34:22 EDT (-0400)
  mixing POV code with C++ (Message 1 to 10 of 29)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Daniel Fenner
Subject: mixing POV code with C++
Date: 9 Feb 1999 23:15:51
Message: <36C107FA.E5776109@public.uni-hamburg.de>
Hi everyone !

Has anyone tried to mix the official POV source code with self-written
C++ code ?
I am using VC5.0 and the compiler does not even recognize the C++
spezific keywords.


Post a reply to this message

From: Roberto Pellagatti
Subject: Re: mixing POV code with C++
Date: 10 Feb 1999 02:28:59
Message: <36c1353b.0@news.povray.org>
Daniel Fenner ha scritto nel messaggio
<36C107FA.E5776109@public.uni-hamburg.de>...
>Hi everyone !
>
>Has anyone tried to mix the official POV source code with self-written
>C++ code ?
>I am using VC5.0 and the compiler does not even recognize the C++
>spezific keywords.

The files have a *.c extension, so the compiler disables C++ syntax. Try to
force C++ compilation: I don't know if there is such an option, you can
anyway rename the files from *.c to *.cpp and try.

Hi


Post a reply to this message

From: Nigel Stewart
Subject: Re: mixing POV code with C++
Date: 10 Feb 1999 08:37:55
Message: <36c18bb3.0@news.povray.org>
>The files have a *.c extension, so the compiler disables C++ syntax. Try to
>force C++ compilation: I don't know if there is such an option, you can
>anyway rename the files from *.c to *.cpp and try.


Also, remember to expose you c interface via extern "c" {  <prototypes> }

As an example header, that compiles in both C and C++ for VC5.0:

#ifdef __cplusplus
extern "C"

#endif

///////////////////////////////////////////
//
// C Interface for TarFileSystemDatabase
//

void       TF_caseSensitive(int flag);

int        TF_addTarFile(const char *filename);
int        TF_addTarFiles(const char *directory);

FILE         *TF_file(const char *filename,const char *mode);
unsigned long TF_sizeOf(const char *filename);

//
//
/////////////////////////////////////////////

#ifdef __cplusplus
}
#endif


Post a reply to this message

From: Nieminen Mika
Subject: Re: mixing POV code with C++
Date: 10 Feb 1999 11:55:57
Message: <36c1ba1d.0@news.povray.org>
"Nigel Stewart" <nigels> wrote:
: #ifdef __cplusplus
: extern "C"

: #endif

...

: #ifdef __cplusplus
: }
: #endif

  How can this work?

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp. -*/


Post a reply to this message

From: Rudy Velthuis
Subject: Re: mixing POV code with C++
Date: 10 Feb 1999 14:16:20
Message: <36c1db04.0@news.povray.org>
Nieminen Mika schrieb in Nachricht <36c1ba1d.0@news.povray.org>...
>"Nigel Stewart" <nigels> wrote:
>: #ifdef __cplusplus
>: extern "C"


/* insert: */

{


>: #endif
>
>...
>
>: #ifdef __cplusplus
>: }
>: #endif
>
>  How can this work?


Then it will work. I've seen this in *all* (Windows-)API header files I've
ever seen.


Post a reply to this message

From: Daniel Fenner
Subject: Re:Re: mixing POV code with C++
Date: 11 Feb 1999 15:49:35
Message: <36C3426B.32FC9456@public.uni-hamburg.de>
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 ?


Thanx
      Daniel


Post a reply to this message

From: Jon A  Cruz
Subject: Re: mixing POV code with C++
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

From: Thorsten Froehlich
Subject: Re: mixing POV code with C++
Date: 12 Feb 1999 02:25:01
Message: <36c3d74d.0@news.povray.org>
In article <36C3426B.32FC9456@public.uni-hamburg.de> , Daniel Fenner 
<Dan### [at] publicuni-hamburgde>  wrote:

> 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.

Some compilers allow to enforce this with a cdecl declaration of a function.
Instead of
void foo();
you would write
void cdecl foo();
However, cdecl is _not_ an ISO C or ISO C++ keyword and might not work with
your compiler.

> 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 :->.

Hmm, this is strange. Where were these changes required? In the core code or
in the platform specific code? The core code itself should compile without
error using a C++ compiler...if it does not, it would be very interesting
where VC had problems.


    Thorsten


Post a reply to this message

From: Jon A  Cruz
Subject: Re: POV source errors
Date: 12 Feb 1999 03:14:33
Message: <36C3E3A8.E381FEDB@geocities.com>
Thorsten Froehlich wrote:

> Hmm, this is strange. Where were these changes required? In the core code or
> in the platform specific code? The core code itself should compile without
> error using a C++ compiler...if it does not, it would be very interesting
> where VC had problems.
>

Just as an aside, when I built the source using VC 5, I get about 710 warnings.
In my experience this is not the best state to leave code in, so what's the
current status on this? (i.e. is it a known and desired state, just something
that needs time to get to, just something to annoy MS compiler users... :-)


Post a reply to this message

From: Ron Parker
Subject: Re: POV source errors
Date: 12 Feb 1999 08:17:40
Message: <36c429f4.0@news.povray.org>
On Fri, 12 Feb 1999 00:17:44 -0800, Jon A. Cruz <jon### [at] geocitiescom> wrote:
>Thorsten Froehlich wrote:
>
>> Hmm, this is strange. Where were these changes required? In the core code or
>> in the platform specific code? The core code itself should compile without
>> error using a C++ compiler...if it does not, it would be very interesting
>> where VC had problems.
>>
>
>Just as an aside, when I built the source using VC 5, I get about 710 warnings.
>In my experience this is not the best state to leave code in, so what's the
>current status on this? (i.e. is it a known and desired state, just something
>that needs time to get to, just something to annoy MS compiler users... :-)

You only get 710? :)  Most of them are precision warnings, which are really
kind of a nitpicky kind of warning anyway.  I've always just ignored them,
until I can find the time to sit down and fix every single one, or someone
else can.  There's definitely a lot of float->double->float conversions going
on in various places, but fixing them would be quite a chore.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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