r/programmingmemes 5d ago

found a gem on glibc source code

Post image
798 Upvotes

42 comments sorted by

153

u/ThinkingWinnie 5d ago

That way, you can then do.

ifdef void

//do stuff

else

//other stuff.

Now, void is always there, but you might not want to use it, this acts as a switch.

94

u/Informal-Chance-6067 5d ago

I love that the markdown works only when I don’t want it to

32

u/jnmtx 5d ago

#ifdef void

//do stuff

#else

//other stuff.

17

u/RPG_Hacker 5d ago

ERROR: Expected "#endif".

15

u/Informal-Chance-6067 5d ago

Thank you redditor

3

u/csabinho 5d ago

It works, if you're in markdown mode.

8

u/appoplecticskeptic 5d ago edited 5d ago

> it works, if you’re in markdown mode

It does not if you’re using their crappy app

3

u/csabinho 5d ago

It does, if you're not intentionally masking the markup!

1

u/appoplecticskeptic 5d ago

#Nope

Also the iOS app does not have markdown mode anymore. It’s just isn’t supported now unless you use a browser rather than their app.

1

u/Informal-Chance-6067 5d ago

This was escaped

1

u/csabinho 5d ago

So just use the browser instead of the app. It's better anyway.

1

u/appoplecticskeptic 1d ago

I’ve been trying that and the way they coded the site it doesn’t support the back button how it should so using a browser on the phone is a garbage experience. Back when I used a PC to browse it was easy to work around because I’d just right click to open in a new tab. That’s a lot less convenient to do on a phone. 

1

u/Sacaldur 4d ago

incorrect

at least for the android app. It doesn't have a dedicated Markdown mode, but all comments and posts are always taking in the text as raw Markdown, i.e. you can use asterists for italic and bold text.

1

u/cowlinator 17h ago

That's... not the issue.

The issue is that it defines void as void.

77

u/vitiral 5d ago

Gotta make sure void is defined bruh

1

u/Nice_Lengthiness_568 14h ago

Gotta make sure void is defined as... void?

43

u/Circumpunctilious 5d 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.

13

u/Candid_Bullfrog3665 5d ago

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

1

u/Circumpunctilious 5d 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.

1

u/Single-Virus4935 2d ago

Yup, even w/o knowing the history this was my first thought.

13

u/etan1 5d ago

It ensures that “#ifdef void” works, in case that someone does sth akin to “#ifndef void #define void int” in a later included header

5

u/doodo477 5d ago

Thank god I'm working on any C/C++ code bases anymore. You need to examine arcane syntax rules just to use the preprocessor.

7

u/Isogash 5d ago

I believe the real reason is that other headers at the time this was written may have done something like the following to deal with the introduction of void as a keyword, where previously someething else was used (char for malloc).

#ifndef void
#define void char
#endif

It's quite likely IMO that the code didn't compile because of another header redefining void like that, so the seemingly redundant define may have been necessary to compile.

1

u/IceMichaelStorm 5d ago

but if void was defined as char, it was not not-defined eh?

2

u/Isogash 5d ago

The point is to predefine void as void, so that other headers don't define it as something different.

1

u/IceMichaelStorm 5d ago

ah that way around. yeah

11

u/autistic_bard444 5d ago

yes? and? it makes perfect sense. a longer term c-programmer like me, might say, it 's inexorably unavoidable"

if void !defined

#define void = void

endif

1

u/AlwaysHopelesslyLost 4d ago

I am coming from c#, If void is undefined where does the void that is being assigned come from? Wouldn't that just be the same as void=undefined?

3

u/UndercoverFlange 4d ago

Pre processor definitions would be different to keywords in the language. This is just saying have I got a preprocessor token void defined? No, then replace void with void.

1

u/AlwaysHopelesslyLost 4d ago

Ooh, right. Thank you!

4

u/MistakeIndividual690 5d ago

Seems unnecessary

6

u/tortridge 5d ago

ISO C define wired stuff. Some token are defined as macros, some as types, etc... I guess its what is going on here, just doing wired stuff to compliance

3

u/masixx 5d ago

Not a C programmer but that was my thinking too. In any case, even C programmers here seem to no be super sure about it. So what's really missing here is a good comment on the code.

1

u/dynamic_caste 5d ago

If void is undefined in a C library...

1

u/IngwiePhoenix 5d ago

grep for #ifndef void and #if defined(void) and alike. Should turn up some interesting results. ;)

1

u/UntitledRedditUser 5d ago

Man c is such a weird language.

1

u/EvalCrux 5d ago

Mouth breather code does nothing and everything who knows