Hi All,
I am maintaining some code that looks a bit quirky - but seems to behave as expected. I'd rather not change it, as the interface ("second_function_called" in the below example) is used everywhere, but if anyone believes the code looks illegal, please tell. It's certainly not best practice.
The program is single-threaded. I've simplified it for the purpose of analysis:
Code:
void first_function_called(int a)
{
// pass parameter "a" through to another function for read access only
second_function_called(&a);
}
void second_function_called(int *b)
{
some_struct s;
// Get a copy of b and use it for something
s.some_field = *b;
// Parameter "b" is never manipulated, passing a copy of "b" would have been fine!!!
}
I guess the question is - is taking the address of a function parameter and then passing it off to another function for read access OK? I believe it probably is, as it should just be taking the address of the parameter off the first functions stack space.
Thankyou.