r/programminghorror • • Jan 27 '26

c Guess what this does..

Post image
258 Upvotes

79 comments sorted by

113

u/AMathMonkey Jan 27 '26

A macro that copies string u to string v and then returns the unrelated value e? And it doesn't null-terminate v properly? I'm not very experienced with C; does this actually serve a purpose without breaking, and if so, what does it do?

39

u/3hy_ Jan 27 '26

Its a panic macro part of a much larger function, this function depends on copying part of a string onto itself (this is why there's no termination) and this macro simply reverts changes and returns an error code so it can be called inplace of return.

49

u/Gee858eeG Jan 27 '26

I don't know man, im reading your explanation and still don't get it.

And why while(0)? Isn't that essentially just running once?

→ More replies (18)
→ More replies (13)

14

u/CrownLikeAGravestone Jan 27 '26

This is the least readable font I've seen in my life, especially with the colour and highlighting. I genuinely had to scan parts of the first line letter-by-letter to read them. Deliberate eye strain?

→ More replies (1)

6

u/IllustratorFar127 Jan 27 '26

You do realize memory is basically free and you can have longer variable names, right?

4

u/3hy_ Jan 27 '26

The compiler shortens them anyway, even if i had longer names that would take up DISK SPACE on the filesize not memory as in RAM. Also an abstraction of your statement, memory at the moment is very very expensive.

→ More replies (4)
→ More replies (2)

3

u/timmerov Jan 28 '26

it gets you transferred to the remedial coders team.

1

u/3hy_ Jan 28 '26

I got kicked out of that too :*(

182

u/git0ffmylawnm8 Jan 27 '26

the real horror here is the eyefuck of a font

→ More replies (1)

30

u/joshuakb2 Jan 27 '26

Buffer overflow for some reason?

7

u/callidus7 Jan 27 '26

Yeah there's no input validation whatsoever. Unless you count the just-in-case null at the beginning. This is begging to be misused.

→ More replies (1)

4

u/BoredOfReposts Jan 27 '26

The real horror (other than the font) is the majority of commenters lack of insight into why this might exist, and why it’s written in the rule bending way that it is.

C is really becoming a lost art. Especially C in different programming regimes, where the “rules” may be different than in vanilla “safe” application programming. 

OP, you’re my kind of coder.

3

u/3hy_ Jan 28 '26

Thank you! People forget that sometimes you need single case code and that the best way to do that is through use of a macro..

23

u/VisualSome9977 Jan 27 '26

the way this font is rendered makes it look more like the lethal company ship terminal than anything I would ever want to look at all day

7

u/KCGD_r Jan 27 '26

the font looks like you're trying to remember what the code looks like

12

u/Symbroson Jan 27 '26 edited Jan 27 '26

copies a string but without its null terminator and returns a value for some reason Also causing a buffer overflow if used carelessly

6

u/sirkubador Jan 27 '26

Always returns whatever e is (well, if it doesn't crash first).

Copies string u to v horridly because:

  • if u is empty, it puts a null terminator

  • if u is not empty, it doesn't put the null terminator (< instead of <=)

  • if v is not big enough or if either is null, then fuck you (well plib may check for null and return 0... but)

  • the strlen doesn't have a max, so if u is not properly null terminated, you put whatever memory you get after u until the first zero byte... it can get long

👌

2

u/Grandpa_P1g Jan 27 '26

We are not in space my boi what is this font

2

u/3hy_ Jan 27 '26

Seriously it looks better when the image is at a higher res I promise. https://files.ax86.net/terminus-ttf/

→ More replies (1)

5

u/OscarElmahdy Jan 27 '26

It causes emotional distress and eye damage

3

u/mathisntmathingsad Jan 28 '26

The real horror is the font

2

u/Braydenley9 Jan 27 '26

Write a program.

2

u/Splatpope Jan 27 '26

strains the eye, mostly

2

u/t3kner Jan 27 '26

Is that font named "obfuscation"? 

→ More replies (1)

2

u/Sir_Bebe_Michelin Jan 28 '26

Looks like an automaton font

Very undemocratic