r/C_Programming • u/mttd • Jun 06 '26
Article Getting silly with C, part &((int*)1)[-1]
https://lcamtuf.substack.com/p/getting-silly-with-c-part-and-int1
89
Upvotes
r/C_Programming • u/mttd • Jun 06 '26
8
u/whirlwindlatitude Jun 06 '26
Hahaha mygod. I laughed out loud (like, with actual sounds) when reading that C uses functions therefore it’s a functional programming language. And then I come to the comments and… mygod. I mean, we don’t have to agree on what’s funny or not, but surely we should be able to agree that certain things are not meant to be taken seriously at all? (For certain types of two was good, too.)
34
u/meancoot Jun 06 '26
The first one is silly. It doesn't forward declare
main, it just gives it two K&R style arguments. This is extra silly since the compiler used will accept an actual forward declaration ofmain.The second one uses $ as a type name, a variable name, and a label. Then relies on the GCC extension to take the address of a label to insert the extra ':'. The
[[]]are just pointlessly added empty attribute blocks.20
u/gudetube Jun 06 '26
If I see any of this in a PR I'm going to tell my manager we need to fire that person and replace them with AI.
7
u/darkslide3000 Jun 06 '26
Wait, wait, that's it? You're just gonna drop this on our poor unprepared brain parsers and walk away?
6
u/kev_xb Jun 06 '26
Everyone here not reading the room?
12
u/zhivago Jun 06 '26
Undefined behavior.
2
u/NoBrick2672 Jun 06 '26
i don't think i could understand it right now
2
u/un_virus_SDF Jun 07 '26
The print statement is absolute magic. I love it.
It must print because it executes in order within the commas and the last thing before ; being 'exit', the expression return 'exit' to goto which just jump to the address and act as if the function was called is absolute genius.
2
u/Aspie96 Jun 07 '26
If I'm not mistaken, you're playing compiler roulette here and the order of operations is not guaranteed.
2
u/Lagger625 Jun 06 '26 •
What the FUCK am I reading
1
u/ziggurat29 Jun 08 '26
Z-80, or x86?
1
u/Low_Lawyer_5684 Jun 09 '26
All the articles in series are great: both text and code. I was laughing alot. Greatest example of programmers humor.
-7
u/flyingron Jun 06 '26
All of it is either ill-formed, relies on unspecificed or undefined behavior. Even the text of post makes no fucking sense. What do you mean, remember && has higher precedence than &&?
-4
u/HoiTemmieColeg Jun 06 '26
We certainly do not call C a functional programming. C is imperative and makes doing a lot of functional techniques particularly difficult with a lot of needed extra work. Not that’s being imperative is a problem, just that C certainly isn’t functional.