va_list, as used by printf, holds information about variable arguments.
It is implementation dependant. It loses types and sizes of arguments it
contains.
The purpose of format directive is to collect the right object size and
coerce this shunk of bytes into the expected type.
On ARM (32bits), long long is implemented internally using two 32bits machine
words.
Current code only extends the print precision of long but does not collect
long long.
I don't know the purpose of bounds_check1_test but your proposal, in case
of pv(x), coerces an int to long long which will of course work.
To keep the spirit of initial code it must be:
#define pv(m) printf(sizeof (s->m + 0) == 8 ? "%llx\n" : "%x\n", s->m)
I let the writer of this test choose what to do.
Below this snippet shows that only the format directive is faulty, not the
compiler.
Both tcc and gcc output:
sizeof(l) = 4
sizeof(ll) = 8
l: 12345678 ffffffff
l: 12345678 ffffffff
ll: 0 34567890
ll: 0 34567890
ll: 1234567890 ffffffff
#include <stdio.h>
#include <stdlib.h>
int
main() {
unsigned long l = 0x12345678;
unsigned long long ll = 0x1234567890;
unsigned guard = ~0;
printf("sizeof(l) = %lu\n", sizeof(l));
printf("sizeof(ll) = %lu\n", sizeof(ll));
printf("l: %x %x\n", l, guard);
printf("l: %lx %x\n", l, guard);
printf("ll: %x %x\n", ll, guard); // truncated
printf("ll: %lx %x\n", ll, guard); // truncated
printf("ll: %llx %x\n", ll, guard); // OK
}
-----Original Message-----
From: Tinycc-devel [mailto:[email protected]] On
Behalf Of Edmund Grimley Evans
Sent: Tuesday, December 10, 2019 23:15
To: [email protected]
Subject: Re: [Tinycc-devel] bounds checking
> #define pv(m) printf(sizeof (s->m + 0) == 8 ? "%llx\n" : "%x\n", s->m)
What's wrong with printf("%llx\n", (unsigned long long)s->m)?
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel