The only difference between class
and struct
is that, in the definition of the type, the default access level is private
or public
respectively. Otherwise, and in other contexts (such as this one), they are identical.
class masterStruct
and struct masterStruct
are two names for the same type. There's no casting because there's only one type. C++ allows the keywords to be used interchangeably because the default access level is no more than a minor implementation detail within the definition.
C++ class types (declared with class
or struct
) can be accessed from C functions as long as certain C++ features can't be used. virtual
functions, mixed access protection for members, etc. can affect the layout of the members in memory, so the C compiler won't be able to find them. "POD" (plain old data) classes are a slight superset of what C will understand, because certain kinds of single inheritance are also permitted.
Nonstatic member functions don't add anything to a class in memory, so they don't affect its layout. They're just ordinary functions with special rules for passing an additional argument which implements this
. C doesn't need to know about them, so you can safely #ifndef __cplusplus
them out.
However, it doesn't sound like you're using masterStruct
from C code at all, but you're only passing a void*
through a C library and back to yourself. In this case, POD-ness doesn't make a difference either. The void*
value is just a scalar value, and it will be the same when you pass it and when you get it back. It could point to anything, or to nothing; it doesn't matter.