POV-Ray : Newsgroups : povray.programming : C vs. C++ : Re: C vs. C++ Server Time
28 Jul 2024 20:26:47 EDT (-0400)
  Re: C vs. C++  
From: Ron Parker
Date: 30 Jun 1999 10:36:37
Message: <377a2b75@news.povray.org>
On 30 Jun 1999 06:30:06 -0400, Nieminen Mika wrote:
>  This is true. Moreover, if you want to call a C-function from C++-code,
>you have to declare the function as: extern "C" foo bar(); (because the
>internal naming convention is different for C and C++).
>
>  Btw, how do I call a C++ function from C?

Assuming you mean a global or static method that doesn't take reference 
or class parameters, which is to say one that you can actually call from C, 
just mark the prototypes as extern "C":

#ifdef __cplusplus
  extern "C" {
#endif
    int myfunc1( int, char );
    .
    .
    .
#ifdef __cplusplus
  }
#endif

You may have to write stubs to call static methods.

If you can't change the C++ code, you're still okay.  You can write a C++
wrapper that consists entirely of stub "C" functions that call the name-
mangled C++ versions.


Post a reply to this message

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