You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
I would have a very hard time suggesting all of these caveats. C++ style variadic templates can do the same things while ensuring safety on all compilers with or without special compiler support.
I may, however, link back to this discussion from inside of the document so that it's known that there are methods by which type safety with C style can be addressed.
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.The text was updated successfully, but these errors were encountered: