this post was submitted on 09 Feb 2023
22 points (92.3% liked)

Programmer Humor

32371 readers
360 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 8 comments
sorted by: hot top controversial new old
[–] TheElectroness@lemmy.ml 5 points 1 year ago* (last edited 1 year ago)

I assumed, at first, that it was somehow falling through the infinite loop and accidentally runnning the unreachable function, but it clearly explicitly runs it in the assembler generated...

10f4: 48 8d 3d d5 00 00 00  lea    0xd5(%rip),%rdi        # 11d0 <_Z11unreachablev>
10fb: ff 15 b7 2e 00 00     call   *0x2eb7(%rip)        # 3fb8 <__libc_start_main@GLIBC_2.34>

how odd.

edit: ah, it's called from __start, which suggests that main is being elided entirely by the optimiser, and somehow 'unreachable' is simply becoming a defacto 'main'

[–] dragnucs@lemmy.ml 2 points 2 years ago (1 children)
[–] yogthos@lemmy.ml 2 points 2 years ago

ok yeah didn't work on my machine either

edit: interestingly enough seems to work on some architectures and not others, a friend of mine tried it and it worked for him. I guess that's why it's an undefined behvaior. :)

[–] anders@rytter.me 2 points 2 years ago (1 children)

@yogthos What. That's not possible? 😃

[–] yogthos@lemmy.ml 1 points 2 years ago

my guess is the optimizer detects the infinite loop and removes it

[–] exohuman@lemmy.dbzer0.com 1 points 1 year ago

I can see the whole loop being optimized away, but how does the method that isn’t being called get called?