In this project, I need to get the size of a struct in a header file from within a C file.
I can't include the header file in the C file because the struct contains classes which will not compile in C.
Any ideas?
You could declare in the .h file:
extern const size_t SIZE_OF_MY_STRUCT;
And define SIZE_OF_MY_STRUCT in the .cpp file as:
extern const size_t SIZE_OF_MY_STRUCT = sizeof(MyStruct);
So you would not have the overhead of a function call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With