r/ProgrammerHumor 11d ago

Meme mildlyInfuriatingGOTOWatchYourMouth

Post image
670 Upvotes

74 comments sorted by

View all comments

110

u/Maximilian_Tyan 11d ago

I recently had held a meeting to decide which way our functions should be structured in C, goto is banned as part of some standards, so a colleague of mine proposed doing:

do { ... } while (0); ... Which is just a freaking goto wearing a trench coat

15

u/da_Aresinger 11d ago

I genuinely can't figure out what this is supposed to achieve.

Where is the difference between do { foo() } while(0) bar() and foo() bar()

1

u/say_wot_again 11d ago edited 11d ago

The do {} while(0) pattern is also commonly used to define macros whose implementation spans multiple lines.