-
-
Notifications
You must be signed in to change notification settings - Fork 911
Description
Regarding this: https://github.com/lefticus/cppbestpractices/blob/master/04-Considering_Safety.md#do-not-define-a-variadic-function
Rather than avoiding C-style variadic functions entirely, you should advise to enable type checking for them. This is included in -Wall; you should also suggest -Wformat=2 in the list of useful warnings, as this warns about non-literal format strings etc.
And in the section which currently says not to define variadic functions, you should say, "unless they can be type-checked by your compiler." And if the function is similar to printf(), scanf(), strftime(), etc., it can be. See the "format" attribute described here: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes .
There are times when C-style variadic functions are most convenient, such as making a strftime() method on a user-defined time class. And they can be safe enough.