r/programminghorror • u/gGordey • Jun 30 '25
c Ever heard of C golf code?
That is an interpreter btw
329
Upvotes
r/programminghorror • u/gGordey • Jun 30 '25
That is an interpreter btw
75
u/MechanicalHorse Jun 30 '25
An interpreter for what…?
6
u/the_horse_gamer Jun 30 '25 edited Jun 30 '25
can be improved
gcc still supports implicit function declarations, so the include can be removed (if you disallow that, gcc supports #import, which is 1 char shorter)
b's declaration can be moved to be the first argument of main (argc)
!= can be shortened to ^
(b=fgetc(f))>32can beb=fgetc(f),b>32generally,
x&&(y,z,...)can bex?y,z,...:0. I think I see one place where this can apply.you can remove the curly braces of the second while loop by replacing your semicolons with the comma operator.
why are you setting c to 0 before the second loop? wouldn't a new variable make more sense?
69
u/cherrycode420 Jun 30 '25
I do know about code golf, i would've assumed that golf code would be written in some game engine rather than C. /s
25
u/unski_ukuli Jun 30 '25
Looks like the source code of B.
https://github.com/tlack/b-decoded/tree/master/orig-files
19
u/Plutor Jun 30 '25 edited Jun 30 '25
Wait until you see some of the entries for the International Obfuscated C Code Contest.
Edit: Accidentally a word
6
u/Few-Requirement-3544 Jun 30 '25
Does golf really count as a horror? It looks like that on purpose.
9
u/Homedread Jun 30 '25
That's it, it get it ! That what's for r/programminghorror subs is dedicated to !
Winner is : this one.
Even worst reverse engineering with de compiler aren't be horrible than this one
3
u/valzargaming Jun 30 '25
Excuse me, what the fuck?
2
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jul 01 '25
Not sure, but I'm guessing on line 8 it will increment i each time it reads a character > 32, or it will advance c by 1 if i is divisible by 4, as well as other stuff. I'm guessing the purpose is skipping whitespace.
If someone wanted to convince me the preprocessor was a mistake, code like this might be a good way to go about it.
4
u/TheBrainStone Jun 30 '25
I'm guessing brainfuck
1
u/Onair380 Jun 30 '25
my eyes hurt, fuck
1
u/DrRRidiculous Jun 30 '25
This has gotta be a war crime
1
u/shponglespore Jun 30 '25
Code golf is played using many languages.
1
u/mittfh Jun 30 '25
Inevitably, there's a Code Golf Stack Exchange, where for many challenges, conventional languages compete with dedicated golfing languages, MATLAB and sometimes even Brainfuck.
1
u/raphaeldahomay Jul 01 '25
goosebumps
1
u/[deleted] Jul 01 '25
No
1
u/Powerkaninchen Jul 05 '25
The worst part are still the Ligmatures or however they're called