this post was submitted on 15 Aug 2024
679 points (98.4% liked)

Programmer Humor

19149 readers
1214 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

Which will probably be never.

you are viewing a single comment's thread
view the rest of the comments
[–] nexussapphire@lemm.ee 2 points 4 weeks ago (10 children)

I forgot to assign a variable, now it crashes %5 of the time. It's wild how c doesn't default variables to null or something.

[–] CodeMonkey@programming.dev 9 points 4 weeks ago* (last edited 4 weeks ago) (5 children)

C does exactly what you tell it, no more. Why waste cycles setting a variable to a zero state when a correct program will set it to whatever initial state it expects? It is not user friendly, but it is performant.

[–] marcos@lemmy.world 7 points 4 weeks ago (3 children)

Except that this is wrong. C is free to do all kinds of things you didn't ask it to, and will often initialize your variables without you writing it.

[–] nexussapphire@lemm.ee 1 points 4 weeks ago (1 children)

Machine code would be a better example of what he's talking about imo. Not an expert or anything of course.

[–] marcos@lemmy.world 3 points 4 weeks ago (1 children)

Odds are that your computer doesn't export any language where it will do exactly as you say (amd64 machine code certainly won't execute exactly as written). And how much difference it makes varies from one language to another.

But the specific example from the OP, of uninitialized variables, is one of those cases where the C spec famously goes completely out of line and says your code can do whatever, run with a random value, fail, initialize it, format your hard drive, make a transaction on your bank account... whatever.

[–] Hack3900@lemy.lol 2 points 3 weeks ago

Coding in C but if I don't initialize a Variable the compiler formats my drive! (Not Clickbait)

load more comments (1 replies)
load more comments (2 replies)
load more comments (6 replies)