Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 07. Dec 2024, 01:30:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vj04v9$2lq17$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Mozilla Thunderbird
On 06/12/2024 22:30, Scott Lurndal wrote:
Ike Naar <ike@sdf.org> writes:
On 2024-12-06, Bart <bc@freeuk.com> wrote:
My language:
>
println =a,=b # 13 characters, 0 shifted
>
(And that space is optional!) In C (assume the existence of stdio.h):
>
printf("A=%lld B=%f\n",a,b); # ~28 characters, 8 shifted
>
Enough said.
>
Looks like a cherry-picked example.
How would this (slightly modified) C statement be notated in your language:
>
printf("a:%lld b:%g\n",a,b);
>
?
Or
printf("a:%2$8.8lld b:%1$10.2g",b,a);
In this case I'd just write it like this:
printf("a:%2$8.8lld b:%1$10.2g",b,a)
ie. calling printf via an FFI. It's marginally shorter than C since I don't need the semicolon.
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.)
I'd typically do this stuff like this:
const fmta = "8.8", fmtb = "10.2"
fprint "a:# b:#", a:fmta, b:fmtb
Here I don't need to care what the exact types of a and b are. I mean, what goes in place of ? here:
printf("%?", a+b*c);
Assume only that a, b, c are numeric types, which might be opaque types exported by some header.
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.
If I do 'print ++i, ++i, ++i', it gives me 1,2,3 always. (Because this print is not a function call.)