this post was submitted on 04 Jun 2025
134 points (97.9% liked)

Programmer Humor

36167 readers
324 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 0 points 2 days ago* (last edited 2 days ago) (9 children)

sha1.c

Yeah, a hash function actually just looks like that intrinsically, though. Being impenetrable is the point.

[โ€“] [email protected] 3 points 2 days ago* (last edited 2 days ago) (8 children)

There are plenty of sha1 implementations that are more readable and sensible and less readable and sensible. This portion is simply an manually unrolled loop (lmao these gcc nerds haven't even heard of Gentoo) of the hash chunk computation rounds. Hash functions aren't "impenetrable" they're just math. You can write math programmatically in a way that explains the math.

The point of this post is actually things like x[(I-3)&0x0f]. It's entirely the same concept as coercion to manipulate index values this way. What's funny is that void pointer math, function pointer math, void pointers and function pointers in general are typically seen as "beyond the pale" for whatever reason.

Beyond that if you know C you know why this is written this way with the parens. It's because C has fucked up order of operations. For example a + b == 7 is literally "does adding a + b equal 7", but if you write a & b == 7 you would think it means "does a AND b equal 7", but you'd be wrong. It actually means does b equal 7 AND a.

Furthermore a & (b ==7) makes no sense because b == 7 is a boolean value. Bitwise ANDing a boolean value should not work because the width of the boolean is 1 bit and the width of the int is 8 bits. ANDing should fail because there's 7 void bits between the two types. However the standard coerces booleans in these cases to fit the full width, coercing the void bits to 0's to make bitwise ANDing make sense.

Beyond that asking what the memory size of a variable in C is a fools errand because the real answer is "it depends" and "it also depends if someone decided to ignore what it typically depends on (compiler and platform) with some preprocessor fun". Remember how I said "void pointers" are beyond the pale? Yeah the typical "why" of that is because they don't have a known size, but remember the size of something for C is "it depends". ๐Ÿคท

Almost every language has idiosyncratic stuff like this, but some let you make up your own shit on top of that. These kinda low hanging fruit jokes are just people virtue signaling their nerddom (JS bad am rite guis, use a real language like C), when in reality this stuff is everywhere in imperative languages and typically doesn't matter too much in practice. This isn't even getting into idiosyncracies based on how computers understand numbers which is what subtracting from 0x5F3759DF (fast inverse square root) references.

[โ€“] [email protected] 3 points 2 days ago (1 children)

b == 7 is a boolean value

Citation needed. I'm pretty sure it's an int.

[โ€“] [email protected] 2 points 2 days ago* (last edited 2 days ago)

Yeah you're actually right, it's an int in C since K&R C didn't have bool, however it's a bool in C++. I forget my standards sometimes, because like I said this doesn't really matter. It's just nerd trivia.

https://en.cppreference.com/w/cpp/types/type_info/operator_cmp.html

load more comments (6 replies)
load more comments (6 replies)