I found this in some code of mine. I felt that using a struct member to pass to a function that was in the same source file, and not used elsewhere was a stylistic error.
I'm unsure how many are doing this, and I can see that the check would not work if I was calling a function I did not control the declaration for (eg library function). At any rate, it seems odd to pass an object with full scope, then also an object that the function already has access to again.
This is perhaps arguably worse (?), if the struct is passed as const &, and the int as &, as one is circumventing the cost-ness of the object (but it compiles just fine). Practically this was not the case in my code, so I am unsure how often this crops up in the real world.
struct MYSTRUCT
{
int a, b;
};
int func(MYSTRUCT s, int var)
{
return s.a + var;
}
int main()
{
MYSTRUCT s;
s.a=s.b=1;
return func(s,s.b);
}
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I found this in some code of mine. I felt that using a struct member to pass to a function that was in the same source file, and not used elsewhere was a stylistic error.
I'm unsure how many are doing this, and I can see that the check would not work if I was calling a function I did not control the declaration for (eg library function). At any rate, it seems odd to pass an object with full scope, then also an object that the function already has access to again.
This is perhaps arguably worse (?), if the struct is passed as const &, and the int as &, as one is circumventing the cost-ness of the object (but it compiles just fine). Practically this was not the case in my code, so I am unsure how often this crops up in the real world.
Thanks!