Question Details

No question body available.

Tags

c language-lawyer scanf conversion-specifier c23

Answers (2)

Accepted Answer Available
Accepted Answer
April 18, 2026 Score: 15 Rep: 234,764 Quality: Expert Completeness: 60%

Where in the C23 draft (or in any C standard) does it mention the corresponding argument for the conversion specification %n shall be a pointer to int

The exact type is specified by the length modifier as specified in section 7.23.6.2p11. It states that the hh, h, l, ll, j, t, and z modifiers can be applied to the n format specifier to specify that the argument points to a char, short, long, long long, intmaxt, ptrdifft, or size_t respectively.

Starting with C23, the documentation for the d, i, o, u, and x format specifiers were updated (and b was added) to explicitly state that a missing length modifier means the argument is a int or unsigned int . Prior to that, they were the same as n in that this wasn't explicitly stated.

Given that 7.23.6.2p11 states that length modifiers apply to n going back to at least C11 and that the documentation for d, i, o, u, and x were updated, this is likely an oversight.

Had your code used %lln as the full format specifier you would have gotten the expected results.

April 18, 2026 Score: 5 Rep: 27,753 Quality: Medium Completeness: 50%

In the standard, many of the other conversion specifiers state one of the following:

Unless a length modifier is specified, the corresponding argument shall be a pointer to int.

Unless a length modifier is specified, the corresponding argument shall be a pointer to unsigned int.

The fact that such as sentence is missing from the description of the n specifier is, as far as I can tell, a defect in the standard.

The statement in the standard about the n specifier

The corresponding argument shall be a pointer of a signed integer type.

is insufficient, because as correctly pointed out in the question, a long long int is also a "signed integer type".