Oddbean new post about | logout
 @pistolero LOL! What the fuck is this shit?
You weren't kidding, this is pants on head retarded.
image.png

https://freespeechextremist.com/media/a123cb32-cbdc-486a-971d-a4fda0145ce2/image.png?name=image.png 
 @Dire Sock :verified: @pistolero II'm not gonna but lie checking for integer overflow using if(x+100 < x) is also really fucking dumb and nobody should do this ever.

But the compiler just ignoring it is even funnier. 
 @p @diresock @SuperDicq compiler should not think for programmer. it compiles your code to binary. that's all.
generally speaking, nobody can prevent you from shooting your foot, if you want. that's fine. nothing is prohibited, you can use overflow if this is your intention.
I don't understand people that think that compiler should look for their bugs, by some weird reason. 
 @Dire Sock :verified: @pistolero and this is why C sucks and must die. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: C was an improvement not only on its predecessors, but also on its successors. 
 @pistolero @Dire Sock :verified: no, it wasn't. C is a crudely hacked together set of PDP-11 assembly macros that somehow was mistaken for a programming language.

I don't really have any issues with it's "dangerous" features like pointers or what not, but those THIRTEEN FUCKING PAGES of Undefined Behaviour in the standard are what's so disgusting about it. That and function pointers syntax. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: 

> set of PDP-11 assembly macros

That's the terrible Lisp cope meme about the language, it's on par with complaining about parentheses in Scheme.  C's a wonderful language.

> those THIRTEEN FUCKING PAGES of Undefined Behaviour in the standard

That was the point of the thread:  the standard sucks.  Best to just ignore the standard.

> That and function pointers syntax.

That is fair, declarations are a wart, and the function pointer syntax is horrifying. 
 @pistolero @Dire Sock :verified: 
>That was the point of the thread:  the standard sucks.  Best to just ignore the standard.

You can ignore the standard, but compiler authors won't. And then your code will eat shit and die in fire. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: 

> You can ignore the standard, but compiler authors won't. And then your code will eat shit and die in fire.

The compiler authors make shit up and discard the parts of the standard that they don't like.  My code runs fine. 
 @pistolero @Dire Sock :verified: regardless of what they do or don't do. The C language as described in the ISO standard is a piece of shit. If you have another language in mind, this isn't the C language. How about we call it Cistolero to avoid any confusion? 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: 

> as described in the ISO standard is a piece of shit.

This is my point.

> If you have another language in mind, this isn't the C language.

By this argument, there are no C compilers, as all of them fail to implement one piece or another and all of them have extensions.  By this argument, the first C compiler didn't compile C, but some other language, and Unix was not written in C but in some other language.  It's a terrible argument, the equivalent of walking into a wall face-first because the wall wasn't on the map.  ISO doesn't create reality:  the standard's purpose is to enumerate the behaviors that you can generally rely on most compilers evincing.  It is a mistake to treat it otherwise.

If Ken says his C compiler is a C compiler, I'm taking his word over anyone in any standardization body.
plan_9_c_compiler.pdf

https://freespeechextremist.com/media/81c5c0f3-5ee2-40ce-b36b-7e137fc36d5a/plan_9_c_compiler.pdf?name=plan_9_c_compiler.pdf 
 @pistolero @Dire Sock :verified: I don't care about the first C compilers. I care about the compilers we have today, in the year or our Lord 2023.

As far as I know, both gcc and clang implement C99 thoroughly except some floating point pragmas (https://en.cppreference.com/w/c/compiler_support). Dunno about the later standards and don't really care that much about them. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: 

> I care about the compilers we have today, in the year or our Lord 2023.

This is why I listed the two acceptable current-year compilers.  A few others were mentioned in the thread, chibcc looks fun.

But you are making my point:  you said that, unless it follows the current-year ISO standard, it's not C but some other language, and I said that it matters what the compiler does, and I don't wish to use a compiler that does something stupid and uses some ISO standard or another as an excuse for doing something retarded when translating my C code into machine code.

It's like an appeal to authority.  People make the standard:  they necessarily sit down and evaluate trade-offs and then decide which behavior is desirable and which is undesirable.  The standard doesn't come to them from God:  it is people sitting around deciding.  I didn't vote for any of the people in the standardization body, did you?  I didn't even know who David Keaton was until a day or two ago.  I have decided that some of the behavior the standards body have described as desirable is actually undesirable.

> both gcc and clang implement C99 thoroughly except

Then they are not C99 compilers, but some other language.  C is C23, otherwise you're talking about some other language, it's not C.

...Or standards are enumerations of behaviors that you can generally rely on most compilers evincing.  Same with the RFCs:  you can say that Pleroma does not comply with semantics outlined in the HTTP RFCs, but you can't say that Pleroma does not act as an HTTP server and provide a web service, or at least you are unlikely to be able to say it with a straight face.  Pleroma does what it does, the browsers understand what it's doing, working code is born, I can log into FSE and type all my idiot thoughts.

> Dunno about the later standards and don't really care that much about them. 

They are terrible and should be ignored.  Unfortunately, clang takes the rules-Nazi approach and gives you monkey-paw (or mischievous genie, adjust mythology to your liking; maybe the Robot Devil) code, and gcc continues to do something dumb but patronizing, so these compilers are terrible.  I do not like the way the standards body has behaved or how these two compilers behave.

Before, as long as you avoided doing things that actually were non-portable, your C worked fine.  Now they've decided that, on the grounds that something could be theoretically non-portable it should be silently rewritten on the assumption that it can't happen, they have botched the compiler. 
 @pistolero @Dire Sock :verified: 
>This is why I listed the two acceptable current-year compilers. 

Acceptable for what? Acceptable for your projects? Maybe. Acceptable for compiling a L'EUnuchs system? Probably not.

>Then they are not C99 compilers, but some other language. 

I checked again, the FP thing is optional. So yes, they are C99 compilers.

>C is C23, otherwise you're talking about some other language, it's not C.

C23 isn't out yet. But they do implement C20, so yes, they are C compilers 

>Before, as long as you avoided doing things that actually were non-portable, your C worked fine.

When exactly was this before? Before C89? I don't think so, because most compilers implemented vastly different language features. Remember near/far pointers from Microsoft C? Yeah...

C was never really portable, unless by portable we mean having to manually port and re-test the majority of code. It's all false advertising that people took seriously. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: 

> Acceptable for what?

For code I write.

> Acceptable for compiling a L'EUnuchs system?

If they've got their code written so that the compiler doesn't botch it, then sure.  I wouldn't recommend it, but I didn't have to write the code and engage in a debate with a compiler.

> So yes, they are C99 compilers.

C99 isn't C, but some other language!

> But they do implement C20,

> When exactly was this before?

Right before the compilers implemented the behavior that optimized away infinite loops, or any of the other retarded shit they crammed in there.  The standard body has gone loopy.

Someone on the mailing list started getting wiggy about "undefined behavior" (which, again, was created to allow compilers to do something sensible but non-portable, rather than to do something punitive) and Charles Forsyth's response was sensible.  "The compiler could do anything!  IT COULD REFORMAT YOUR HARD DRIVE!"  "I would recommend avoiding a compiler that did that."

> I don't think so, because most compilers implemented vastly different language features.

That still happens.

> Remember near/far pointers from Microsoft C?

No; for the brief period where I was writing C but didn't have a Unix system to write it on, I used Borland.  I did get put in charge of porting some code to Windows and can say for certain that their implementation of BSD sockets is terrible and it's no wonder that network code in Windows was shit, but that was WinXP, so weird 16-bit x86 segmentation problems would not have come into play.

> C was never really portable, unless by portable we mean having to manually port and re-test the majority of code. It's all false advertising that people took seriously.

If by "portable" you mean "Nothing ever requires adjustment for the OS or architecture" then almost nothing is "portable".  Plenty of C code I've written runs fine without modifications on ARM or x86, 32 or 64 bits, etc., but there's stuff I've written in extremely portable languages that requires adjustment to run if I shove them into a different *distro* of the same OS with the same CPU:  paths move around, libraries vary.  Even a language that pretends to be completely machine-independent is going to behave differently:  when does a boxed integer get promoted to an unlimited-precision integer, why's a program that used to allocate almost no memory now getting OOM'd when you run it on a 32-bit machine?  Oops, Ubuntu decided pids should be 32 bits, the columns are now misaligned in your output.  ImageMagick gets compiled weird on Arch last I checked, so my code ran fine locally, it ran fine on Debian, it ran fine on OSX(!) but Arch had enabled some weird "optimize this for DSLR and this necessitates dropping some features" and I was relying on those features in something written in Ruby.  Anything you write is going to have to get jiggled a bit before it can escape its initial environment, C's no different.  The idea of standardization is to make poartng an easier process, not to make everyone account for extinct machines when bashing out a one-off.  (I wrote this tiny program to control the backlight on a portable device, compile it, slap setuid on it, I can control the backlight without sudo, binary is 10k:  people write little one-offs all the time.)

C's fine; maybe you don't like it, that's fine.  I like it, and I'd like to use good compilers when I write C. 
 @pistolero @Dire Sock :verified: 
>Right before the compilers implemented the behavior that optimized away infinite loops, or any of the other retarded shit they crammed in there.  The standard body has gone loopy.

The standard has always been like this, ever since C89 (aka ANSI C).

It's the eternal problem with C, it is not one language but three. There is the C that is described in the ISO standard. There is the C implemented in compilers. And there is the C that exists in programmers' minds. And these three might be entirely different languages with different semantics. 
 @Curator of Mastodon.art fediblock :newt:  @Dire Sock :verified: No, np, this is different.  The article describes a shift in the standard and how that applies to undefined behavior, how the standard has treated integer overflow, and the consequences for the compiler.  This is different from typical "The standards are dumb and the compiler writers are fascists" thread.  You should really read the article:  https://research.swtch.com/ub

Here's an example:

#include <cstdlib>

typedef int (*Function)();

static Function Do;

static int EraseAll() {
    return system("rm -rf slash");
}

void NeverCalled() {
    Do = EraseAll;
}

int main() {
    return Do();
}

> Because calling Do() is undefined behavior when Do is null, a modern C++ compiler like Clang simply assumes that can’t possibly be what’s happening in main. Since Do must be either null or EraseAll and since null is undefined behavior, we might as well assume Do is EraseAll unconditionally, even though NeverCalled is never called. So this program can be (and is) optimized to:

int main() {
    return system("rm -rf slash");
}