Re: What is the Point of Static or Constant Variables?

Static and constant variables have two similar but different purposes. Constant variables by there name are constant and can never be changed. This is helpful in many situations when you want a value but you never want it to be accidentally changed. You could say just never change it, but can you guarantee that this will never happen? What happens if you are using a codebase amongst a whole team of junior and senior devs? Its just better to make things immutable/constant if there is no need for them to change.
Static on the other hand is a bit more advanced. Many times, especially in games, static classes are used for back-end services like audio systems. things that are declared static are allocated memory in their own little static area away from normal scoping. generally this means they have scope for the life-time of a program is running but this is not always the case. Static variables inside functions retain their memory across all the times a function is called in a program. This is nice if you are running a counter and need to keep track of how many times something happens. Static class data members are available across all instances of a class with the same value. Static methods are likewise available to all instances of a class, but can not be accessed through the standard this pointer. static methods can only access other static functions and other static variables. Finally, static class instances or objects get their primitive data members initialized to 0 but not usr defined data members. they are in scope throughout the life-time of a program.
Read this article for more info. and This page on game programming patterns is a good application of static classes.
Something can be static and constant, static and not constant, or just constant. They are not the same.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Liam via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : dardar via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector

Reply via email to