I am attempting to use C code from C++ and am having trouble sharing a struct between the two languages.
Currently I am able to get everything to compile by defining the struct in both the C++ file and the C code. For example:
MyFile.cpp
Code:extern "C" { struct SomeStruct { short One[904]; short two; }; extern struct SomeStruct theStruct; } . . theStruct.two = 1;
defines.h
SomeCode.cCode:struct SomeStruct { short One[904]; short two; }; extern struct SomeStruct theStruct;
There are other C files that use theStruct and they haveCode:struct SomeStruct theStruct; . . theStruct.two = 0;
in them.Code:extern struct SomeStruct theStruct;
These snippets are from the real code with names changed but it shows what I currently have. I want to access the same variable of the struct type from both C++ and C.
I have been struggling with this for a while now and can get it to compile doing it this way but I am unsure if it is the correct way to do this.
Any help is greatly appreciated.
Thanks.




Reply With Quote