this post was submitted on 11 Feb 2025
227 points (94.5% liked)

Programmer Humor

20736 readers
1391 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 2 years ago
MODERATORS
 
all 16 comments
sorted by: hot top controversial new old
[–] [email protected] 22 points 1 week ago (3 children)
[–] [email protected] 24 points 1 week ago (1 children)

Not needed, main in C++ implicitly returns 0 if there is no return

[–] [email protected] 1 points 1 week ago (1 children)

Should ≠ Needs to

You can do it, and it will work, but it's unclean and not best-practice. I wouldn't be surprised if it's undefined behaviour.

[–] [email protected] 22 points 1 week ago (1 children)

Just to clarify. It is defined behavior - there's plenty of undefined behavior in C but that ain't one of them.

[–] [email protected] 2 points 1 week ago

Interesting feature, I had no idea. I just verified this with gcc and indeed the return register is always set to 0 before returning unless otherwise specified.

spoiler

int main(void)
{
    int foo = 10;
}

produces:

push   %rbp
mov    %rsp,%rbp
movl   $0xa,-0x4(%rbp) # Move 10 to stack variable
mov    $0x0,%eax       # Return 0
pop    %rbp
ret
int main(void)
{
    int foo = 10;
    return foo;
}

produces:

push   %rbp
mov    %rsp,%rbp
movl   $0xa,-0x4(%rbp) # Move 10 to stack variable
mov    -0x4(%rbp),%eax # Return foo
pop    %rbp
ret

[–] [email protected] 18 points 1 week ago (3 children)

>What is C++? A miserable huge pile of "should"s

[–] [email protected] 8 points 1 week ago

Love me some Castlevania++

[–] [email protected] 1 points 1 week ago (2 children)

should have a space after „>” and two new lines after „?”.

I guess markdown is miserable as well.

[–] [email protected] 5 points 1 week ago

Hey now, markdown serves it's purpose. It's not great, but as a web dev, I don't want people expecting full WYSIWYG editors in every website cause fuck that!

[–] xtools 3 points 1 week ago

not being able to master markdown might hint at why the commenter is struggling with C++

[–] [email protected] 1 points 1 week ago* (last edited 1 week ago)

Still love it tho. You can make it whatever you want!

[–] [email protected] 2 points 1 week ago

It likely does, at some point within the ellipsis.

[–] onlinepersona 2 points 1 week ago (1 children)

Didn't you know that C++ programmers are better than compilers at checking code for safety though? And if they aren't, it's a skill issue.

/s

Anti Commercial-AI license

[–] [email protected] 3 points 1 week ago (1 children)

It's all worth it for that sweet sweet 50ms speedup!/s

[–] [email protected] 1 points 5 days ago

And sensible compile times.

I'm trying to write a game in Bevy but my laptop's Intel 7400 taking almost a minute to compile even small changes is really killing me.
I've looked up rustc compile times on different CPUs and am seriously considering getting a new laptop with a Snapdragon X Elite or something in that vein for this.