+ 2

What is the purpose of this obfuscated C code?

Here is a snippet of some strange C code I found. Capital letters are int functions and lower case variables are ints. Assume they've all been defined. while(x&&D(x-1),(x/=2)%2&&(1)){ ... ... u/2&(x/=2)%2&&(c=P(t,c),u=S(4,13,-4,t),t=9) } Why x&&D(x-1)? Does the && operator change the operands? If not, it doesn't do anything... right? Why (x/=2)%2&&(1) instead of (x/=2)%2? I thought a&&1 is the same as a. Why does the last line update some vars but not assign the overall result to anything?

15th Apr 2023, 3:08 AM
Jacob Dreiling
Jacob Dreiling - avatar
14 odpowiedzi
+ 5
In some cases we need to take short-circuiting into effect. For example 'x&&D(x-1)' is if(x != 0) { D(x-1); }, or shorter if(x) D(x-1); Similarly for the last line of the loop body. That can be rewritten as x /= 2; if( (u/2 == 1) && (x % 2 == 1) ) { c = P(t, c); u = S(4, 13, -4, t); t = 9; } The condition of the if-clause can, of course, be shortened. But the &&(1) remains a mystery.
15th Apr 2023, 5:40 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 3
Ani Jona 🕊 feels like &&(1) is redundant, since that part is always true.
15th Apr 2023, 7:15 AM
Bob_Li
Bob_Li - avatar
+ 3
Bob_Li right, so why it is there I cannot explain :)
15th Apr 2023, 7:17 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 3
A rather weak one, would it not be? 🤔
15th Apr 2023, 7:22 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 3
Could also be a misspelling of (x/=2)%2&(1) I don't know if the above excerpt is free of bugs...
15th Apr 2023, 7:25 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
hard to tell.
15th Apr 2023, 7:28 AM
Bob_Li
Bob_Li - avatar
+ 1
obsfucation?
15th Apr 2023, 7:17 AM
Bob_Li
Bob_Li - avatar
+ 1
Ani Jona 🕊 thank you for the answer! I forgot about short circuiting, but now it makes way more sense. I think the &&(1) is needed just because this code has many more copies of (x/=2)%2&&, which were all compressed into macros. The code is for something called Loader's number, for context: https://googology.fandom.com/wiki/Loader%27s_number
15th Apr 2023, 5:15 PM
Jacob Dreiling
Jacob Dreiling - avatar
+ 1
Jacob Dreiling https://googology.fandom.com/wiki/Loader%27s_number are you sure it's not a spell for summoning ancient demons...😅 Ok, I will show myself out....
15th Apr 2023, 6:20 PM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li it really does look like a dark summoning spell haha
15th Apr 2023, 7:02 PM
Jacob Dreiling
Jacob Dreiling - avatar
+ 1
Jacob Dreiling Ok, I think I found a more beginner friendly explanation for Loader's Number. Doesn't mean I totally get it, but if I squint my eyes, I can fool myself into thinking that I do...🤨 https://googology.fandom.com/wiki/User_blog:Upquark11111/An_Explanation_of_Loader%27s_Number
16th Apr 2023, 1:53 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li that looks very helpful indeed. I'm going to try reading it over the next few days
16th Apr 2023, 3:02 AM
Jacob Dreiling
Jacob Dreiling - avatar
+ 1
I skimmed that article and have a question. This is pretty heavy on the lambda calculus. Would using something like haskell or clojure be better suited for this task?
16th Apr 2023, 11:09 PM
Bob
0
Hey
16th Apr 2023, 1:39 AM
Jayden Winsor
Jayden Winsor - avatar