To support my understanding (and probably to reasonify the understanding in first place), let me add my two cents.
For a minute, let's see the footnote 282, as mentioned in quote. It says,
See ‘‘future library directions’’ (7.31.11).
and in §7.31.11
Lowercase letters may be added to the conversion specifiers and length modifiers in
fprintf
and fscanf
. Other characters may be used in extensions.
Which mentions nothing about the relation between a CS and its argument (if any). So, the "validity" of a CS is not dependent on the supplied argument.
Now, that said, couple of more pointers
Point 1 :: Please note the mention of the phrase "conversion specification", not conversion specifier, in the quote. As per chapter §7.21.6.1/P4,
Each conversion specification is introduced by the character %
. After the %
, the following
appear in sequence:
Zero or more flags [...]
An optional minimum field width [...]
An optional precision [...]
An optional length modifier [...]
A conversion specifier character [...]
and we have definitive lists for all the elements mentioned in
- P5, field width and precision
- P6, flags
- P7, length modifier
- P8, conversion specifier
Thereby, there is (or should be) no relation with the supplied argument to identify the "validity" of the conversion specification.
To complement this understanding, borrowing words from the comment by Ajay Brahmakshatriya
"I think the operating word here is "corresponding". The first sentence says that if in the string exists a specifier which is not valid. If not, then each specifier is matched with its corresponding argument. Then the second statement says about type matching.....I think the second example does not lie in the first category because "corresponding" is not used"
Point 2 :: On the other hand, spec is quite distinct and clear about a "mismatch" between the CS and the supplied corresponding argument type. So, that is a different case altogether.
Now, for example, in case, both the cases are combined, it's hard to tell which condition causes the UB, but it's UB, for more than one reason, for sure.
Example:
printf("%D", str);
following the question.
*printf()
- without saying that. I could see a different answer for*scanf()
. E.g. does the format need to be "correct/matching" if the specifier is not reached as part of the scan? Hmmmm. (I think it does) – Isthmian"%S"
as a valid conversion specification and is therefore not invalid, but valid - for that compiler. – Isthmian