r/ProgrammerHumor • • Aug 01 '22

>>>print(“Hello, World!”)

Post image
60.8k Upvotes

5.7k comments sorted by

View all comments

927

u/[deleted] Aug 01 '22

0[array]++;

491

u/FCrosser Aug 01 '22

Wonderous Worlds of C

There could be an entire book written about sacrilegious C code fragments.

257

u/AceJohnny Aug 01 '22

194

u/KenHuffman Aug 01 '22

46

u/TheCaconym Aug 01 '22

First I thought: that's disgusting. Then I read the hint file and tested it. This is incredible, well done.

68

u/StuntHacks Aug 01 '22

What in the name of Ritchie

18

u/Hidesuru Aug 01 '22

I hope you're ashamed of this, lol.

(Just kidding well done!)

14

u/thegreatpotatogod Aug 01 '22

Any relation to David A Huffman, known for Huffman Coding?

24

u/KenHuffman Aug 01 '22

Yeah, he was my uncle. Cool guy. Surfed into his seventies near Santa Cruz.

→ More replies (7)

11

u/GinWithJennifer Aug 01 '22

Your work makes me want to vomit. Thanks

10

u/[deleted] Aug 01 '22

Can you explain what the code does? It reads stdin and outputs some pattern but I couldn't understand or recognize the pattern.

34

u/KenHuffman Aug 01 '22

This program converts ASCII text to Braille and vice versa.

Feed the source code to the program as input to the program and it will display its documentation.

This is from https://www.ioccc.org/1996/huffman.hint file...

Judges' comments:

To use:

make huffman

echo 'Huffman Decoding' | ./huffman

Try:

echo 'seeing or feeling is believing' | ./huffman

echo 'CC OR NOT CC' | ./huffman | ./huffman

If you are still confused and want to read a spoiler, check out the source and it will be clear as mud! And for a misleading hint, consider who won! :-) And if you really can't see what is going on, here is an extra spoiler:

./huffman < huffman.c

This entry was very well received at the IOCCC BOF.

Selected notes from the author:

This filter program is really not obfuscated code. It compiles cleanly with an ANSI C compiler and comes with user documentation that even a blind person could read.

The program is a bi-directional filter with the output of the program suitable for its input. The output of this program, when used as input, undoes the original program filtering.

This program accepts any alphanumeric text that has lines less than 100characters. The user is encouraged to use the program's source as input to the executable. This program is best appreciated on a tactile monitor.

16

u/brimston3- Aug 01 '22

The fact that it is self documenting when run on its source as input really takes the cake here.

11

u/KenHuffman Aug 01 '22

True, it isn’t very obfuscated. 🤣

12

u/miraj31415 Aug 01 '22

Brilliant! The output from using the program's source code as input to the executable is:

THIS PROGRAM CONVERTS ALPHANUMERIC CHARACTERS

TO BRAILLE AND VICE VERSA

WHEN ASTERISKS ARE FOUND

EXCEPT LINES THAT START

WITH A POUND SIGN WHICH

ARE IGNORED

OUTPUT FROM THIS PROGRAM

IS SUITABLE FOR ITS INPUT

1234567890 0987654321

THE QUICK BROWN FOX

JUMPS OVER THE LAZY DOG

→ More replies (14)
→ More replies (4)
→ More replies (1)

156

u/Classy_Mouse Aug 01 '22

I have to admit, I am too dumb to figure out how to Google this one. Based on my limited knowledge of C:

0[] would treat 0 as a pointer (as in the 0th address)

array is just a pointer, so it is some other address.

So 0[array] would take the array-th address starting from 0 (which is just array) and return the referenced value. Then you increment that.

Is that right? If so, gross. If not, I'm scared to know how that actually works.

154

u/TheCaconym Aug 01 '22 edited Aug 01 '22

You are perfectly correct, except array is not a pointer, it's a numerical value: the offset from address 0x0.

In C, foo[x] is basically *(foo+x) but more readable.

85

u/VladVV Aug 01 '22

You just made me realise that array[index] and index[array] should technically always resolve to the same memory address.

Now that I think about it, I guess that's the intent of the original comment, I just didn't think about it this way before I saw yours.

→ More replies (15)
→ More replies (8)
→ More replies (6)

532

u/a-slice-of-toast Aug 01 '22

extends something, i don’t know what, but something

59

u/carglassfred Aug 01 '22

It actually increases the first element of the variable 'array' ;)

The logic goes kinda like this: Since 'a[1]' is the same as '*(a+1)' And since the plus operator doesn't care about order 'a+1' is the same as '1+a' - therefore '1[a]' can be understood as '*(1+a)' which is the same as '*(a+1)' and also the same as 'a[1]'

TLDR: the square bracket is just addition + dereferencing and therefore doesn't care about order.

→ More replies (4)
→ More replies (9)

19

u/Sheepherder_Loud Aug 01 '22

Increment the value at the start of the array by 1?

→ More replies (16)

26

u/Willinton06 Aug 01 '22 edited Aug 01 '22

Fucking C++ man

61

u/Ahajha1177 Aug 01 '22

This is C. Granted, it works in C++, but blame C for this monstrocity.

11

u/d_b1997 Aug 01 '22

Monstrosity? The simplicity is beautiful

→ More replies (3)
→ More replies (1)
→ More replies (17)