this post was submitted on 11 Feb 2025
199 points (94.6% liked)

Programmer Humor

20429 readers
2979 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 13 comments
sorted by: hot top controversial new old
[–] 30p87@feddit.org 21 points 23 hours ago (3 children)
[–] syklemil@discuss.tchncs.de 15 points 20 hours ago (3 children)

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

[–] shotgun_crab@lemmy.world 6 points 17 hours ago

Love me some Castlevania++

[–] riodoro1@lemmy.world 2 points 19 hours ago (2 children)

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

I guess markdown is miserable as well.

[–] xtools@programming.dev 2 points 12 hours ago

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

[–] kboy101222@sh.itjust.works 4 points 18 hours 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!

[–] 30p87@feddit.org 1 points 20 hours ago* (last edited 20 hours ago)

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

[–] Kwdg@discuss.tchncs.de 22 points 22 hours ago (1 children)

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

[–] 30p87@feddit.org 1 points 22 hours 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.

[–] xmunk@sh.itjust.works 20 points 21 hours 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.

[–] FuckBigTech347@lemmygrad.ml 2 points 16 hours 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

[–] pancake@lemmygrad.ml 2 points 23 hours ago

It likely does, at some point within the ellipsis.