I have a C++ struct with methods inside:
struct S
{
int a;
int b;
void foo(void)
{
...
};
}
I have a userprogram, written in C. Is it possible to get a pointer to a S-struct and access the member aand b?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can access the members of a
structwritten in C++ from a C-program given you ensure that the C++ additions to the struct syntax are removed:The memory layout of structs and classes in C++ is compatible with C for the C-parts of the language. As soon as you add a vtable (by adding virtual functions) to your struct it will no longer be compatible and you must use some other technique.