On Thu, 4 Dec 2003 01:17:05 +0200, "Cristian Tota"
<cr***********@vion-software.ro> wrote:
Hi,
I'd appreciate any thoughts on mixing C++ and C code. I have a project that
uses a given C interface, the rest of the project can be either in C or C++.
What would be the recomended design pattern in this case? C++ allows for a
better design, but integrating the code with the C code isn't straight
forward, it becomes rather messy. Code readability and maintenance are
important, since the project will grow in the future. Maybe someone could
speak from personal experience about this.
Thanks,
Cristian
stand-alone functions, you can wrap in
extern "C"
{
int foo(){}
}
If you need to expose classes to C, you can concatenate the class name
to the function names, make them extern "C" and pass to them an extra
static pointer to substitute the this pointer. Member variables become
file-scope static variables.
A few issues back of CUJ there was an article on state machines which
presented object oriented code techniques in C to go with it.
But, usually, for interfacing you'll probably just need interface
classes --i.e. just functions, probably static, which you can collect
into ,C files, which in turn call the C++ code.
Hope it helps.
Cheers!