I love that this code compiles and runs, intuition says it shouldn’t; but now I have to build it and look at the machine code to learn something. Thank you in advance for a fun evening!!
That’s the address of some other variable on the stack? I don’t remember the c calling convention, but the return address lives there, along with other variables.
Weird, another usage of static I didn't know about. But that doesn't require runtime evaluation; is it actually guaranteed that an expression there can have side effects at runtime?
5
u/Overcooked-Cabbage Apr 16 '22
Could anyone explain the significance of &x-3? Like, why are we subtracting from a memory address, then casting it and dereferencing it altogether?
3
u/jediwizard7 Apr 16 '22
Wait so that's actually evaluated? I always thought it was like a comment that did literally nothing
165
u/naptastic Apr 16 '22
My first thought was "well, at least it's the non-recursive solution"
I'm not a smart man...
134
u/Sequel_Police Apr 16 '22
What. The fuck.
Also is the union there just to make it spicy or does it have a point? It's been too long since I've done anything serious in C.
48
u/iamasuitama Apr 16 '22
At this rate we might as well be writing Perl
34
u/ChocolateBunny Apr 16 '22
Is this part of the standard or is this some gcc goodness like statement expressions?
26
u/Furry_69 Apr 16 '22
Why? Why am I here, if not to suffer?
48
u/[deleted] Apr 16 '22
Please someone explain this so I can slip it into my code ...
18
u/sidewaysthinking Apr 16 '22
The real thing that makes this difficult to figure out is how it relies on knowing how the compiler arranges the stack when calling the function.
51
u/SammyzABanana evil >:) Apr 16 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
13
u/Razakel Apr 16 '22
To quote Linus Torvalds, this is the product of a seriously diseased mind.
19
u/dingodongubanu Apr 15 '22
MY EYES, IT BURNS!!!!!
3
u/gngmntl Apr 16 '22
Welp. Down to 1 brain cell.
1
u/slazil Apr 16 '22
How does recursion terminates? How does int s[0] make it terminate?
1
u/oli-capybara Apr 20 '22
noooOOOO
0
u/jasonkunda Apr 16 '22
Completely unrelated but what is that text editor it looks nice
0
u/jasonkunda Apr 16 '22
Completely unrelated but what is that text editor?
0
u/[deleted] Apr 16 '22
[deleted] — view deleted comment