|
BDE 4.14.0 Production release
|
Macros | |
| #define | BSLA_SCANF(FMTIDX, STARTIDX) |
Provide a macro for checking scanf-style format strings.
scanf format and argumentsBSLA_SCANF is activeThis component provides a preprocessor macro that indicates that one of the arguments to a function is a scanf-style format string, and that the arguments starting at a certain index are to be checked for compatibility with that format string.
BSLA_SCANF(FMTIDX, STARTIDX): This annotation instructs the compiler to perform additional checks on so-annotated functions that take scanf-style arguments, which should be type-checked against a format string.
FMTIDX parameter is the one-based index to the const format string. The STARTIDX parameter is the one-based index to the first variable argument to type-check against that format string. For example: BSLA_SCANF_IS_ACTIVE: The macro BSLA_SCANF_IS_ACTIVE is defined if BSLA_SCANF expands to something with the desired effect; otherwise BSLA_SCANF_IS_ACTIVE is not defined and BSLA_SCANF expands to nothing.
This section illustrates intended use of this component.
Suppose we want to have a function that will populate a list of ints and floats with random numbers in the range [ 0 .. 100 ).
First, we define our function:
Then, in main, we call populateValues properly:
Next, we observe that there are no compiler warnings and a reasonable set of random numbers are output:
Now, we make a call where the arguments don't match the format string:
Finally, we observe the following compiler warnings with clang:
| #define BSLA_SCANF | ( | FMTIDX, | |
| STARTIDX | |||
| ) |