Why does "% I64d" give strange output when it is used several times in the same format string?

While I was solving the problem of programming on codes, I found that when the format specifier "% I64d" was used several times in the same format string, for example:

long long int a, b, c;
a = 1, b = 3, c = 5; 
printf("%I64d %I64d %I64d\n", a, b, c);

there was a way out

                                                               1                                                                0                                                                3 

However, when I shared each qualifier, for example:

long long int a, b, c;
a = 1, b = 3, c = 5;
printf("%I64d ", a);
printf("%I64d ", b);
printf("%I64d ", c);
puts("");

the output was, as expected:

                                                           1                                                                3                                                                5 

Here is an ideal link to see the above code snippets in action: http://ideone.com/f2udRB

Please help me understand why this is happening? If this behavior is undefined, how is this output displayed? How can I understand the reasons when such unexpected results sometimes appear?

+4
source share
2

%I64d printf() 4- , GNU printf I " ", 64 "pad to 64 chars", d 32- .

8- , a, b, c long long.

2 ^ 32, ( 4- )

1 0 3 0 5 0

3 printf, . %lld, printf() 8- .

+10

, , ? undefined, ?

, undefined, . ideone 32-, , ( V ABI) . , :

    push    0
    push    5
    push    0
    push    3
    push    0
    push    1
    push    OFFSET FLAT:.LC0
    call    printf

, , ( ) .

+3

Source: https://habr.com/ru/post/1665312/


All Articles