justin = { main feed , music , code , askjf , pubkey };
Ask Justin Frankel
No reasonable question unanswered since 2009!

Suggested topics: programming, music, sleep, coffee, etc.

Note: please do not ask questions about REAPER features, bugs or scheduling, use the forums instead.


Name: Ask: Human (enter yes):
[back to index] | [unreplied] | [replied] | [recent comments] | [all]

Question: Have you ever thought to keep all global vars in one structure instead of g_barman?
Asked by Jeremy, the kid (178.147.28.x) on March 1 2013, 10:13pm
Reply on March 1 2013, 10:21pm (edited at March 1 2013, 10:29pm):
    Reasons against a global struct storing all global vars:
    1. You usually only initialize some of them to values other than 0 -- if using a single struct, the 0 variables will be encoded as 0s in the binary, whereas with individual variables the linker can put all 0-initialized values in the BSS.
    2. The file that defines that struct will probably be a pain to merge.

    I don't really see the upside.

    As a side note, I absolutely insist on all structs/classes that have non-trivial methods to have their member data begin with m_. Having to work with code that does not do this is completely maddening. Using g_ and s_ prefixes for global / static data is also a must*, and generally never causes any problem for me (even if sometimes you end up at the top level with 'static int g_foo' or 'int s_foo' which is misleading).

    * Note: static data without the s_ prefix is OK to me if the scope of that data is very small

Comment:
    Your Name:   -- Site Owner's Name:  (for human-verification)

    Comment:    

    
  
[back to index] | [unreplied] | [replied] | [recent comments] | [all]
Copyright 2025 Justin Frankel. | RSS