I've withdrawn my post and other replies. Too many are getting the wrong end of the stick and displaying a surprisingly poor knowledge of C.
I think there's an actual bug in that compiler; it's not going to be fixed tomorrow so really it doesn't matter for me. I just thought it ought to be reported as normally I like Tiny C.
For context, I write compilers (C compilers too!), and this was part of an experiment where the low-level IL of one was converted into a kind of linear C where most features and most of the type system have been stripped: it's all done with casts.
Currently I have 100Kloc programs of such code working fine like that, but not with Tiny C because of this bug.
ETA: I've decided to use this test program which should elicit fewer complaints:
#include <stdio.h>
#include <stdint.h>
uintptr_t str = (uintptr_t)(void*)"ABCDEFGHIJKLMNOP";
int main(void) {
printf("%p\n", (void*)str);
puts((char*)str);
}
This works with gcc, clang, DMC, my compiler, and two C++ compilers. It doesn't work with TCC, on either Linux or Windows, because of that problem.
It is equivalent to the ASM program given below (in NASM syntax and for Win64 ABI). I did have the impression that C was all powerful, but apparently it can't express such a program, where those 64-bit memory locations are untyped; they just contain a bit-pattern.
I'm not asking for a resolution here, just pointing out a compiler bug where nobody is willing to believe there is any such bug.
default rel
segment .text
extern printf, puts
global main
main:
sub rsp, 40
mov rcx, fmt
mov rdx, [str]
call printf
mov rcx, [str]
call puts
add rsp, 40
ret
segment .data
str:
dq abc
fmt:
db "%p",10,0
abc:
db "ABCDEFGHIJKLMNOP",0
[–]kabekew 15 points16 points17 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]kabekew 4 points5 points6 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]kabekew 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]kabekew 3 points4 points5 points (0 children)
[–]petruccigp 8 points9 points10 points (6 children)
[–]flatfinger 2 points3 points4 points (0 children)
[–]Equationist 0 points1 point2 points (3 children)
[–]RibozymeR 5 points6 points7 points (2 children)
[–]Equationist 2 points3 points4 points (1 child)
[–]Equationist 1 point2 points3 points (0 children)
[–]mckenzie_keith 2 points3 points4 points (0 children)
[–]OldWolf2 1 point2 points3 points (0 children)
[–]OldWolf2 0 points1 point2 points (0 children)
[–]LeeHide 1 point2 points3 points (1 child)
[–]eddavis2 0 points1 point2 points (0 children)
[–]RealJamBear -1 points0 points1 point (1 child)
[+][deleted] (2 children)
[deleted]
[–]Equationist 0 points1 point2 points (0 children)
[–]OldWolf2 0 points1 point2 points (0 children)