Sujet : Re: question about linker
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 07. Dec 2024, 03:01:47
Autres entêtes
Organisation : None to speak of
Message-ID : <87r06kxnck.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Gnus/5.13 (Gnus v5.13)
Bart <
bc@freeuk.com> writes:
[...]
However, your attempt to catch me out on something I might not support
has backfired, since it doesn't work even in C. This program:
>
#include <stdio.h>
int main(void) {
long long a = 123456789876543210;
double b=1.0/3;
printf("a:%2$8.8lld b:%1$10.2g",b,a);
}
>
compiled with gcc 14.1 on Windows, produces:
>
a:%2$8.8lld b:%1$10.2g
>
On WSL and gcc 9.x it works, sort of. (Matching the label in the
format string with the $ value and the argument looks confusing.)
As you know, the issue is the runtime library implementation of printf,
which is not part of gcc. Some runtime libraries implement this POSIX
feature. Others do not, and I'm not surprised that a Windows-specific
library implementation would not. (It works with several C libraries
I've tried, including glibc and musl.)
gcc will warn about it with command-line options you've already been
told about.
[...]
Here's another issue:
>
#include <stdio.h>
int main(void) {
int i=0;
printf("%d %d %d", ++i, ++i, ++i);
}
>
3 compilers give me output of 1,2,3; 3,2,1; and 3,3,3.
Yes, that's a well known example of undefined behavior in C.
Yes, similar code in other languages might behave differently.
[...]
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */