quote:
why exactly is using globals so dangerous?? besides the risk of acciedently assigning a value to it that you didnt want, what else is the problem with them? is it just read-ability problems, or something else?
Globals aren''t necassarily bad if you still modularize your code. But most people abuse globals, so that''s why they are generally not a good idea to use.
Using the HP example, say you wanted to add another player. But uh-oh, all your functions used the HP variable directly, meaning now you have to go through and pass the HP as a paramter.
One use of globals that is ok is the global string buffer (a pointer to it is returned when you call most c standard lib string functions). You never directly access it, so you don''t have to worry if the standard library suddenly uses two string buffers rather than one (for who knows what reason).