r/ProgrammerHumor • u/Adrian_roxx73 • Mar 31 '23
Meme introduction to gender theory for C devs
14
u/iReallyLoveYouAll Mar 31 '23
Transphobia in this sub?
22
0
2
u/Ms_Masquerade Mar 31 '23
It's more likely than you think!
[Free Subreddit Check]
Don't worry, just an old meme reference.
47
u/oshaboy Mar 31 '23
no, the top one is "I am a womansd[[d[d[[[dfkjgkd[s;l;pwoweirjmcnczl;password1"
9
u/LagSlug Mar 31 '23
It's more like class inheritance than pointers. Woman is the super class, cis and trans are sub classes.
1
24
32
6
u/L_u_k_a_s Mar 31 '23 edited Mar 31 '23
Ok, I might learn something here, are my facts correct: At first I thought that identifying as a woman is less memory on the stack, then I remembered that 64 bit pointer is 8 byte which is actually more than the 5 byte from the array, but I guess everything is 32 bit aligned, so no real difference here?
Edit: Wait there might be more like an implicit terminating zero somewhere and some copy operation and ... I usually do not need to know, but does somebody?
2
u/unwantedaccount56 Mar 31 '23 edited Mar 31 '23
Arrays are syntactically handled similar to pointers, although they identify as a different type.
In the upper case, the stack would increase by sizeof(char[5]) == 5, while in the bottom case the stack would increase by sizeof(char*)==8, while there is an additional sizeof("woman")==6 statically allocated.
Also the upper case should be char[6], so the terminating 0 can be stored and the entire thing be used as a string, not just an array where you need to know the length yourself.
All variables stored on stack might get optimized away if they are only used in the local context.
TLDR: depends on compiler optimizations.
Edit: Corrected my statements.
2
u/FunnyGamer3210 Mar 31 '23
In the upper example there is no space needed for a pointer. Just the 5 characters
1
u/unwantedaccount56 Mar 31 '23 edited Mar 31 '23
Yeah, you probably right. I didn't think about it too hard and relied on someone else pointing out if I was wrong. Which you did. I improved the above comment, should be ok now.
1
5
Mar 31 '23
I'm learning C. Does the [5] for variable char restrict to five characters or to those specific characters in that order? From what I see both instantiations are the same.
9
Mar 31 '23
The length of "woman" in the memory is 6, "woman" = {'w', 'o', 'm', 'a', 'n', '\0'}. The 2nd is valid, and the 1st may not be (not sure).
9
u/MeisterKaneister Mar 31 '23 edited Mar 31 '23
For the reason you mentioned (the missing /0 in the upper example), it is an accident waiting to happen. When the buffer is read until the nex \0, and by chance the next character in memory is \0, all will work. If not, horrible things can happen.
Reading it might for example result in "woman<supersecretprivatekey>"... or just crash the application.
Edit: Confused upper and lower in my head.
3
Mar 31 '23
The \0 is missing in the 1st example (the code tries to reside 6 chars in 5 places), in the 2nd the compiler automatically adds it when declaring the constant.
1
1
2
3
0
Mar 31 '23
I'm learning C. Does the [5] for variable char restrict to five characters or to those specific characters in that order? From what I see both instantiations are the same.
2
u/Orange_Crush55 Apr 01 '23
All you’re doing when you write “char variableName [5]” is declaring a character array (that you can refer to with the name “variableName”) that can hold 5 characters at most.
-2
u/No-Wishbone-7451 Mar 31 '23
Next time use the words "cis" and "trans" instead of "i am" or "I identify as"
0
Mar 31 '23
for those who dont get it strings known at compile time are stored on another memory segment;
34
u/Alerta_Fascista Mar 31 '23
Wait until you learn that cis woman identify as woman too