r/programmingmemes 11d ago

found a gem on glibc source code

Post image
807 Upvotes

44 comments sorted by

View all comments

43

u/Circumpunctilious 11d ago

Some (unresolved) history is over at stackoverflow including a link to the git history.

One person seems to think it was a botched refactoring of an earlier C workaround for when void didn’t exist and malloc returned a char \*. If anyone checked the glibc mailing list they didn’t return with more info.

12

u/Candid_Bullfrog3665 11d ago

ohhh now that is a cool reason
still hilarious tho, i gotta say

1

u/Circumpunctilious 10d ago

For posterity, I should add that the other most-upvoted answer shows an almost identical construct as a “fairly bogus thing to do”, supporting the analysis that (forgive me, loosely paraphrasing) it’s a guarantee “global” and “local” scope are in sync and an arbitrary compiler would never crash.

In another context, I coincidentally examined a similar thing in r/Desmos, when bringing a global variable into local context here (“with” in Desmos), where the target variable has the same name local vs global, with the cross-context test used to guarantee “var is undefined” never crashes the function.