What does the printf / snprintf% N format character do? (not% n)

Some old code went through and found:

char buf[...];
int i = 1, j =2;
snprintf(buf, "%d-blah_%d-blah_%N", i, j);

Please note that there are only two parameters passed to vararg, but 3 format lines.

He is typing

1-blah_2-blah_0

It is impossible to find this in any documents. What does% N do?

+4
source share
2 answers

According to standard documentation (for example, POSIX printf ), it does %Nnot specify anything (therefore, there may be undefined behavior and, of course, undefined behavior in standards).

GNU glibc printf . ( ) register_printf_function %N. , GNU glibc ( , GCC format .).

+7

Microsoft CRT. , %N , .

<VSDIR>/VC/crt/src/output.c, VS2013 :

enum CHARTYPE {
    ...
    CH_SIZE,            /* 'h', 'l', 'L', 'N', 'F', 'w' */
    ...
};

'N' . , 'F'. (case ST_SIZE) 'N', 'F' 'L' ( !) - -op.

, VS2013 1-blah_2-blah_, 0.

+1

All Articles