in all translation units. That way I can easily keep track of what different parts of the program are doing at any time by modifying a single variable.
That's a nice idea. You can always put a pointer there if you need more state.
It just doesn't work on machines with different int and pointer sizes. On the benefit of interoperability, I suggest you make it a (void*). So one function can set it program_state = (void*)'K'; while some other one can set it program_state ={1, 32, 768}; and yet another can do program_state = "I'm in the middle of something here!";.
12 Comments
tiredofsametab@kbin.social · 10 pts · 3y
Perl actually uses
myandourto do scope.my @foo;
our $bar;
jdr@lemmy.ml · 3 pts · 3y
Young man, could.you explain your shitpost?
fiah@discuss.tchncs.de · 10 pts · 3y
int variable => local scope => my int from the perspective of an instance
static int variable => class scope => our int, for all instances of a class
Bear_with_a_hammer@lemmy.ml · 1 pts · 3y
You know what's funny? In PHP it's backwards :D
fiah@discuss.tchncs.de · 1 pts · 3y
well of course it is!
Lux@lemmy.blahaj.zone · 1 pts · 3y
I said, young man, what the fuck was that post?
thebestaquaman@lemmy.world · 3 pts · 3y
personally I prefer including the file
prog_constants.hint program_state; // Keeps track of stuffin all translation units. That way I can easily keep track of what different parts of the program are doing at any time by modifying a single variable.
marcos@lemmy.world · 2 pts · 3y
That's a nice idea. You can always put a pointer there if you need more state.
It just doesn't work on machines with different int and pointer sizes. On the benefit of interoperability, I suggest you make it a (void*). So one function can set it
program_state = (void*)'K';while some other one can set itprogram_state ={1, 32, 768}; and yet another can doprogram_state = "I'm in the middle of something here!";.ndguardian@lemmy.studio · 2 pts · 3y
I hate how long it took me to get this, but I love it.
azimir@lemmy.ml · 1 pts · 3y
This is a great one. I'm definitely using it in class this fall to explain static variables.
DonjonMaister@programming.dev · 1 pts · 3y
Fun fact: I made this meme to explain my classmates static variables.