Reputation: 13
For the purpose of the question I don't report all the code but just the significant details. I have this function:
void foo(/* SOME OTHER ARGS */ int* len);
This function (that I can't edit and don't want edit since in other circumstances I need len
) creates a file and modifies len
parameter accordingly. In some occasion I don't need len
at all, and hence my question is: is there a way to pass a hard-coded dummy parameter without declaring a dummy variable just for this purpose?
Upvotes: 0
Views: 1470
Reputation: 75062
Elements of compound literals are modifyable, so you can pass its address if the function require valid addresses.
foo(/* SOME OTHER ARGS */, (int[]){0});
Note that most arrays in expressions are converted to an address of their first elements.
More information: c99 - Why are compound literals in C modifiable - Stack Overflow
Upvotes: 1
Reputation: 134346
If you don't intend to use len
, and foo()
is geared up to handle a null-value passed through len
, you can call the function like
foo (validparams, NULL);
Upvotes: 0