BDE 4.14.0 Production release
|
Macros | |
#define | BSLA_FORMAT(FMT_IDX) |
Provide a macro to indicate that a return value is a format string.
printf
-style format spec. in n
th arg.BSLA_FORMAT
is activeThis component provides a preprocessor macro to indicate that an indexed argument of a function is a printf
-style format specification, and that the function will return a printf
-style format string with an equivalent specification.
BSLA_FORMAT(FMT_IDX)
: This annotation specifies that the so-annotated function takes an argument that is a valid format string for a printf
-style function and returns a format string that is consistent with that format. This allows format strings manipulated by translation functions to be checked against arguments. Without this annotation, attempting to manipulate the format string via this kind of function might generate warnings about non-literal formats, or fail to generate warnings about mismatched arguments.
BSLA_FORMAT_IS_ACTIVE
: The macro BSLA_FORMAT_IS_ACTIVE
is defined if BSLA_FORMAT
expands to something with the desired effect; otherwise BSLA_FORMAT_IS_ACTIVE
is not defined and BSLA_FORMAT
expands to nothing.
This section illustrates intended use of this component.
First, we define an enum
, Language
, to indicate the choice of languages:
Then, we define a function, prefixName
, which will take a format string and prefix it with the word name
in the selected language. The BSLA_FORMAT
annotation indicates that the result will be a pointer to a printf
-style format string equivalent to the format string passed to the third argument:
Next, in main
, we call printf
and sscanf
using the return value of prefixName
. No warnings occur when correct arguments are passed:
Now, we call printf
and sscanf
passing arguments that won't match the resulting format string:
Finally, we observe the following warning messages with g++:
#define BSLA_FORMAT | ( | FMT_IDX | ) |