void f(int count, ...){
//whatever
}
struct somestruct{
size_t a, b, c;
};
int main() {
somestruct s;
f(1, s); //what is actually passed?
}
Is the entire struct
copied and passed on the stack? If so are copy constructors called? Is the pointer passed? Is this safe?
Yes, if you pass an lvalue, the lvalue to rvalue conversion will be done, which means calling the copy constructor to copy the object into a new copy and passing that as an argument.
void f(...)
is using bit-wised copy. No default constructor or copy constructor will be generated for your somestruct
as it only has C++ build-in types.
Is this safe?
Yes, this is perfectly safe.
I'll refer you to 'Inside C++ Object Model' chapter 2 The Semantics of Constructors
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