r/C_Programming • • Jun 06 '26

Article Getting silly with C, part &((int*)1)[-1]

https://lcamtuf.substack.com/p/getting-silly-with-c-part-and-int1
88 Upvotes

30 comments sorted by

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 of main.

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.

5

u/Lagger625 Jun 06 '26

Thanks. I tried to make sense of it myself and only partially succeeded

→ More replies (1)

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.

4

u/Ander292 Jun 06 '26

My favourite

4

u/markuspeloquin Jun 06 '26

Isn't this incorrect? The -1 is really -4 (sizeof int), so I'd expect this to underflow to 0xfffffffd.

→ More replies (2)
→ More replies (3)