I have a C struct with associated functions:
struct StructC {
int a;
int b;
};
static inline StructC func1()
{
StructC ret;
//do something with variables ret.a and ret.b
return ret;
}
static inline void func2(StructC var)
{
//do something with variables var.a and var.b
...
}
and a C++ struct:
struct StructCPP {
int a;
int b;
StructCPP func3() //can also be static
{
StructCPP ret;
//do something with instance variables ret.a and ret.b
return ret;
}
void func4() //can't use static here since it operates on the instance variables
{
//do something with instance variables a and b
...
}
};
My question: Which is faster when passing these structs to functions/methods?
Since the C functions operating on StructC are static, only one instance reside in memory, but what happens with the C++ methods in its struct?
Do its methods (func3() and func4()) occupy redundant memory for every instance, or does the C++ compiler optimize it to hold only one instance, so while passing the C++ struct, only the instance variables, a and b, are passed?
which function call to these functions is faster (if there is any difference)?:
void functionA(StructC var); //StructC as argument
void functionB(StructCPP var); //StructCPP as argument
(The program is a mixture of C and C++)