Search code examples
clanguage-lawyerc11c17

Is the term "format specifier" a synonym for term "conversion specifier"?


Both the C11 and C17 standards use terms “conversion specifier” and “format specifier”. Are they synonyms? If yes, then why introducing the synonyms? If no, then what is the difference between them?


Solution

  • "Format specifier" appears to just be a semi-formal term. The only normative text using the term is the inttypes.h headline 7.8.1, with no explanation provided of what a "format specifier" is. Though inttypes.h mixes the size and type/signedness into a single term, because of the nature of the stdint.h types. It says that d in PRId32 is a conversion specifier and then PRId32 as whole is supposedly a format specifier? While fprintf/fscanf separates for example "length modifiers" and "conversion specifiers", where l in %ld would be the length modifier and d the conversion specifier.

    The fprintf and fscanf functions define a term conversion specification, for example C17 7.21.6.1, emphasis mine:

    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 that specifies the type of conversion to be applied.

    The above is also the formal definition of the term conversion specifier. Then these functions list valid conversion specifiers as d, i, f and so on.

    It would appear that "format specifier" and conversion specification mean the same thing.