tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

compilers and unused args in functions



In sh, I have a whole set of functions that are called
via a function pointer in a data struct

	(*p->func)(arg);

One of those functions needs a 2nd arg, which means that
to keep compatible function profiles these days, I need
to add the extra arg to all of them

In the ancient past I would have just added an extra arg to
the one that needs it, and the call site, and all the other
functions would just have continued using the one arg that
they have used before (all they need) and the function which
needs the extra arg would declare that, and use it, and all
would have been good.

However, I don't believe that works any more, the compiler
checks the profile of the functions added to the data struct
(the "p->func = function;" type things) to make sure that the
function given there has the same profile as the "func" field
is declared to be a pointer to, and the actual declarations of
the functions need to match their profiles.   Sigh - C used to
be such a nice flexible language...

So, now I have all these functions (but one) with an arg they don't
need, and have no use for.

I could add something stupid like
	arg = arg;
or something to use the value (but then the compiler is likely to
warn about arg being assigned a value which is never used) - but
even if that would work, is at least potentially meaningless extra
code generated.

Assuming that compilers today do, or might in the future, complain
about functions being declared with args that they never use, what's
the recommended remedial action for situations like this?

(But please, I have no intention at all of turning them all into
varargs functions, just to avoid this problem, I'd rather just turn
the warnings off, and potentially lose cases where there really is an
error found when an arg got forgotten to be used as it should be).

kre



Home | Main Index | Thread Index | Old Index