2

In C I know that one uses format specifiers to indicate a data type or to specify, which data one should expect from Input. My question would be what the difference between a format specifier and conversion specification is?

Gregory
  • 177
  • 6
  • https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160 – 0___________ Nov 10 '20 at 17:04

1 Answers1

4

Since you mention 'input', this presumably refers to the scanf() family of functions. The terminology is basically the same for the printf() family of functions too, but they have more possible elements in a conversion specification.

A conversion specification is a complete unit such as %*13lf.

The (format) conversion specifier is the last letter, such as f in the example above.

See C11 §7.21.6.2 The fscanf function:

¶3 … Each conversion specification is introduced by the character %. After the %, the following appear in sequence:

  • An optional assignment-suppressing character *.
  • An optional decimal integer greater than zero that specifies the maximum field width (in characters).
  • An optional length modifier that specifies the size of the receiving object.
  • A conversion specifier character that specifies the type of conversion to be applied.
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Interesting. Was pretty sure these are used interchangeably. – Eugene Sh. Nov 10 '20 at 17:06
  • It depends whether you look at the standard or listen to and read common parlance. In the standard, they're distinct. In common use, the terms are mixed up. – Jonathan Leffler Nov 10 '20 at 17:07
  • However, in https://stackoverflow.com/a/67805947/1778275 user @Lundin concluded that _"Format specifier" appears to just be a semi-formal term_. – pmor Jun 02 '21 at 21:06
  • And user @Lundin concludes as well: _It would appear that "format specifier" and conversion specification mean the same thing_, According to this conclusion `format specifier` != `conversion specifier`. – pmor Jun 02 '21 at 21:13
  • 3
    @pmor: The C standard does not define 'format specifier'. There is a difference between a 'conversion specification' and a 'conversion specifier'. A conversion specifier is a single letter denoting the basic type of conversion (what will be recognized); a conversion specification is a complete multi-character unit starting at `%` and ending with the conversion specifier (consisting of at least 2 characters, therefore). Using undefined terms (such as 'format specifier') leads to confusion because no one knows (for sure) what you're referring to. It's why standards define terms. – Jonathan Leffler Jun 02 '21 at 21:46
  • Thanks. Yes, the difference between 'conversion specification' and 'conversion specifier' is clear. Also @Lundin concludes (in the question linked linked above) about 7.8.1: _PRId32 as whole is supposedly a format specifier?_. – pmor Jun 02 '21 at 21:54
  • @pmor: I don't see anything about 'format specifier' in [§7.8.1](http://port70.net/~nsz/c/c11/n1570.html#7.8.1) of the C11 (draft) standard — except in the section heading "Macros for format specifiers" and the footnote in the section. That might almost be worthy of a request for a corrigendum to the standards body. There are also two other footnotes (one under `fprintf()` and one under `fscanf()`) that reference 'format specifier'. [Forward ¶8](http://port70.net/~nsz/c/c11/n1570.html#Forewordp8) says that "…notes, footnotes, and examples are also for information only" — not normative. – Jonathan Leffler Jun 02 '21 at 22:32