93
« on: July 01, 2018, 07:08:40 am »
In fact, a static variable will have 2 different behaviours depending on how you declare it.
Within a function, it will remain in memory in that function for all the program's life. Try to avoid that.
A global static variable is one that you can only see within one c file.
It's useful if you need variables for some functions but you don't want them to become available for the whole program.
Try to avoid global variables and use local variables and pointers as much as possible.
Also, a bool is 32 bits with SGL, so you waste 31 bits.
A better way is to use bitmasks.
Like say your enum says alive = 1<<17;
Then
ship->status |= alive; //sets the ship to alive
ship->status &= ~alive; //sets the ship to dead
To check if the ship is alive :
If (ship->status & alive) //same as == true
If ((ship->status & alive)==0) //same as == false
You could then use status for 31 others true/false flags in the same maner.