what's wrong with that?
*a++
doesn’t increment the value pointed to by `a`, it increments `a` itself. The value remains intact. int increment(a)
{
return a+1;
}
void somefunc()
{
int b = 5;
b = increment(b);
printf("b now %d\n", b);
}that's latest GCC, at -O3
But yes, sadly I think it's still generally advisable to avoid returning large structs by value.
Note that this has nothing to do with RVO; as I understand it, RVO is about eliding copy constructors, not actual memory copies, and c has no copy constructors and so gets 'RVO' in all cases.
For the use cases that are too expensive to use functions, macros can be used instead.
However that is only if C++ cannot be used at all, otherwise don't bother.
T get_t(int how, char **error);
int get_val(T *v);
One could rewrite these as struct get_t_res {T; char *};
struct get_t_res get_t(int);
struct get_val_res {int; T};
struct get_val_res get_val();
But what do you think of it?Noob mistake