What is an URFP?
Oftentimes it is useful to declare a function to match a particular signature but without making use of the parameters it consumes. Inevitably, this causes a bunch of griping from static analysis tools and compilers.
A short example,
1 2 3 4 5 6 7 8
And when we feed it to gcc, we get:
1 2 3 4 5 6 7 8 9 10 11 12 13
Why does this happen—other than the compiler flag, I mean?
Most frequently in some kind of OOP language we find ourselves overriding a method on a class. That override may not use all of the arguments supplied by the caller: for example, a stub
update( float dt) method in a game entity’s logic.
Fixing URFP In C/C++
So, to fix this, we define a simple macro:
Then, we just use it at the top of a function to shut up the compiler.
1 2 3 4 5 6 7 8 9 10
Note that in C++ this isn’t always safe, because of type overloading. One can imagine a situation wherein some clever person has overridden the
void typecast operator on their class, and so when you URFP it away it still does something unseemly instead of disappearing. This is a failure of the C++ language.
JSHint and JSLint will both complain to you if you don’t disable the behavior.
In JSHint, the appropriate line to use can be found in the docs:
1 2 3 4 5 6
I tend to always leave this at
strict, because I prefer to get any help from the linter that I can.
The problem is, of course, that this will make the linter scream bloody murder whenever you run it over your source code. So, a moral equivalent to the
URFP above is:
This will let you consume the variable in the function and do nothing, and then the jshint
expr directive will keep the linter from complaining about the lack of invocation or assignment.