This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global Definitions

Hello!

What is the best method to declare some variables global ( more than one .C File should know it ) and still avoid multiple public definitions?

A Global Header File is definitely NOT the key to success ;-)

Thanks for your help!

Parents
  • Most often when I have a global variable, I do like the above. It might be a tick counter or similar that a lot of code would like to be able to access.

    When talking about modules, I often have an accessor function (or in case of C++ often a static factory method that returns a single unique object instance). So, the module does not contain any global variables - only static variables (declared with static keyword or in nameless namespace).

    However, as Andy notes, alternatives can not be discuessed without first clearly state goals or usability requirements.

Reply
  • Most often when I have a global variable, I do like the above. It might be a tick counter or similar that a lot of code would like to be able to access.

    When talking about modules, I often have an accessor function (or in case of C++ often a static factory method that returns a single unique object instance). So, the module does not contain any global variables - only static variables (declared with static keyword or in nameless namespace).

    However, as Andy notes, alternatives can not be discuessed without first clearly state goals or usability requirements.

Children
No data