this post was submitted on 14 Jun 2023
35 points (97.3% liked)

Programmer Humor

32410 readers
1 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 6 comments
sorted by: hot top controversial new old
[–] Xanvial@beehaw.org 3 points 2 years ago

You should add returns ray detected outside of while loop

[–] Attempted_Render@lemmy.fmhy.ml 2 points 2 years ago (1 children)
[–] tj111@lemmy.fmhy.ml 1 points 2 years ago (1 children)
[–] Attempted_Render@lemmy.fmhy.ml 2 points 2 years ago

cosmic ray detected.

[–] chkno@lemmy.ml 2 points 2 years ago* (last edited 2 years ago) (1 children)

Any sane compiler will simplify this into

    function cosmicRayDetector() {
      while(true) {
      }
    }

C++ may further 'simplify' this into

    function cosmicRayDetector() {
      return
    }
[–] LuciferMorningWood@lemm.ee 2 points 2 years ago

Iirc the issue was that while(true) would be removed while it should be replaced with ret and this caused a bug where the binary would execute next function

But I believe this way of cosmic ray detection would work

volatile bool condition = true;
while(condition) {
}
printf("Cosmic ray detected");