answersLogoWhite

0

The first thing to do is wrap the C code so the compiler knows to treat it specifically as C rather than C++:

// Include directives go here.

#ifdef __cplusplus

extern "C" {

#endif // __cplusplus

// C code goes here.

#ifdef __cplusplus

}

#endif // __cplusplus

Often that's all you need to do. However, be aware that C++ uses reserved keywords that C does not not know anything about, so if you have C variables named "this" or "class" or "virtual", etc, then you must rename them throughout the C code.

C does not adhere to the strict type-safety in C++. Therefore all calls to malloc (which returns void*) need to be cast to the specific type. Also, be wary of implicit casts from int to enum. C++ does not support this, but C does.

Also be aware of sizeof() differences. In C, sizeof(char) typically returns 4 (bytes), whereas in C++ it always returns 1 (byte).

User Avatar

Wiki User

11y ago

What else can I help you with?