C Until It Is No Longer C

(aartaka.me)

19 points | by thunderbong 4 days ago ago

3 comments

  • flohofwoe 3 days ago

    I realize it's a joke post, but at least a couple of misleading things at the start demand correction ;)

    > Well, I can always define some booleans myself! ...

    Just always include stdbool.h, C versions before C99 are no longer relevant (even MSVC has mostly caught up since around 2016).

    > Because booleans are nothing but unsigned integers 1 and 0.

    Not really, bool/_Bool is its own native type with a size of 1 byte - IIRC the C standard might probably say 'at least 8 bits' but in reality it's always one byte (it implicitly converts to integer though).

    > typedef char byte;

    Not quite right if you expect `byte` to have a specific signedness, since `char`, `signed char` and `unsigned char` are technically three different types (whether char behaves like a signed or unsigned number depends on the compiler or compile target).

    Also note that the new 'auto' has slightly different behaviour in GCC and Clang, and please only use it when needed (when dealing with unknown or unnamed types).

    As for the rest of the post, please don't do this if you expect other people to ever read your code :)

  • jwilk 3 days ago

    At some point the argument type changed from "unsigned int" to "byte" aka "char". But "char" is signed on many popular architectures. So this

       return c is 127 or c < 32;
    
    no longer does the right thing.
  • jykcyl 3 days ago

    I did almost exactly this when I was an intern at Microsoft in 1990: just the logical tests so that it read better. Everyone had a good laugh but nobody took me seriously and recently an old mentor reached out to me on LinkedIn and still remembered jokes about my fledgling coding style.