Skip to content
Prev 59506 / 63435 Next

sprintf, check number of parameters

Dear Matthias,
On 2/6/21 2:11 PM, Matthias Gondan wrote:
yes, it does.
yes, it does as well
Thanks for the example. I am sympathetic with your concerns about the 
programming style in it: the caller needs to know exactly how "mask" 
will be used, that it would be in a call to sprintf() and what would be 
the indices of the arguments.

The warning has been introduced a while ago and there has not been any 
report yet that it would break existing good style code (particularly 
CRAN packages have been tested extensively), which indicates that 
currently the R code base does not rely on unused $- arguments.

It is hence I think wise to keep the warning to prevent R code base from 
relying on that in the future, because gcc/clang already warn on unused 
$-arguments. Not only that gcc developers must have been thinking hard 
about the same thing before us getting to this conclusion: $- arguments 
are a POSIX extension and gcc/clang are the key compilers for POSIX 
systems, so it is safer to abide by their rules. In principle POSIX may 
mandate that $- arguments are used explicitly in the future (now it is 
rather vague, it seems unused are fine only when last), and even if not, 
deviations from gcc/clang could cause confusion for applications and 
developers using both C/C++ and R.

Best
Tomas