okay but has someone written like. a contrarian c compiler. a c compiler that on purpose, whenever anything is left up to the implementation, does whatever GCC and LLVM don't?
@halcy I've wanted to do this. Just do absolutely absurd, horrible things with lots of side effects.
@halcy I think @womble once told me about doing something similar in order to torture students. Maybe involving a 31-bit ones-complement processor with downright creepy memory layout, implemented in an FPGA, or am I conflating memories? 🤔

@kitten_tech @halcy And CHAR_BIT != 8 and sizeof(void*) != sizeof(long), of course… All of this does exist somewhere, but AFAIK nobody has done all this in one system.

If you want to get real fancy, make an implementation for Setun (a ternary computer):
https://en.wikipedia.org/wiki/Setun

Setun - Wikipedia

@halcy Like when Clang goes "I'mma optimize this null check away because spec says I can assume all uses are non-null, and you accidentally 'used' it three lines earlier"?

Personally I'd go for the "chaos compiler" where whenever something is left to the implementation it just picks a random behavior, including intentionally doing something absolutely nonsensical if the given input results in undefined behavior (it's not against spec for a compiler to insert bounds-checks if it knows the size of the array for certain... it's just that C's ABI makes it next to impossible for the compiler to know it)

@becomethewaifu @halcy I would say the insistence of programmers to use an ancient style of C instead of something as young as 2 decades often makes it next to impossible for the compiler to know the bounds:
https://godbolt.org/z/5hsTe8bP1
(but I agree there also some language problems which prevent one from doing this consistently)
Compiler Explorer - C (x86-64 gcc (trunk))

int f(int n, int (*a)[n]) { (*a)[n] = 1; } int main() { int n = 10; int a[n]; f(10, &a); }

@halcy @mcc I mean. a lot of the implementation-defined stuff is ultimately just up to whatever the underlying CPU does (e.g. signed overflow)
@halcy malicious C compiler that does the worst possible thing with every unspecified behavior
@halcy I wanted to write an adversarial C compiler that tries to screw with you whenever the standard says it can. I believe this will be the final stage of compilers anyways,
DeathStation 9000 - Wikipedia, the free encyclopedia

@halcy
You could fsck a lot of code over by making `sizeof (int) == 2`

That was a lot of fun on the Amiga (SAS vs. Manx compilers). To this day, I still think carefully before using `int`.

@ewhac @halcy still the case if you write code for avr (aka 8-bit arduino) :D
@ewhac @halcy we use routinely a compiler with sizeof(int) == 1, lots of fun.
@halcy if someone writes such a compiler, here is a proposal for complex number implementation…. https://wiesmann.codiferes.net/wordpress/archives/36840
An analogy for Unicode support – how not to do complex numbers…

One thing that really annoys me in computer science is the huge gap between the way human text is understood in programming and how it should actually be done. Mostly programming languages implemen…

Thias の blog
@halcy gccc. "whenever there are cases of undefined behaviour in the C standard, we repeatedly write 0x41 to the target of the operation..."
@halcy the short time I played with it, the Unisys 2200 c compiler felt like it was written in a contrarian way.
Pretty much nothing could be ported to it
@halcy @mcc you know what, fuck you *unsigns your char*

@halcy gcc 1.34 interpreted #pragma as "play hack or rogue"

There are some good real world ones - pointer operations that can fault if the pointer is not valid, ones complement, twos complement but overflows cause an exception. For pre ANSI C the Honeywell L66 was fun. One config was 5 7bit chars and a spare bit per machine word, which sure made "sizeof()" interesting

When gcc first started using all the pointer aliasing opportunities that also created mayhem.

@halcy I remember something like this but I don't remember if it was a C compiler Basically all undefined behaviour was random.
@halcy I've wanted to build that, but even further: an asshole C compiler on top of an asshole POSIX architecture.
Visual Studio C/C++ IDE and Compiler for Windows

Download free Visual Studio IDE to build cross-platform apps for Linux, iOS, Android, IoT, and Windows devices using latest, standards-compliant C and C++.

Visual Studio
@halcy @mcc The Macintosh Programmers Workshop C compiler had saucy errors messages like “A typedef here was a complete surprise”, “The <standard> says you can have 435 characters in this expression; I gave you 500 and you still blew through it”, and “Too many errors; make fewer”.