Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Initialize pointers to NULL in Managers.cpp
tiwag:
--- Quote from: Takeshi Miya on December 13, 2005, 02:12:11 am ---...Should I use the first, because the latter would pollute the global namespace whenever the #define won't?
--- End quote ---
if you are born past 1977 use the latter :)
280Z28:
I only mentioned it because when I did a search in files for g_EditorManager, I did not see an immediate place where it was always initialized. If it was initialized at the declaration it would have saved me a bit of time because there would be no doubt.
thomas:
You may want to use the latter regardless of when you were born, because macros have side effects that are not always visible, and you can always put your consts into a namespace.
The side effect in this case is noticeable if you have many calls to wxString::assign with the macro/const as argument.
If you use a const wxString, the data will be copied exactly once, and assign() will copy a pointer each time. If you use a macro, then assign() will call the CRT strlen, malloc, and memcpy functions each time!
One of the optimizations I made to the code completion tokenizer was replacing
if(blah...)
token = _T("::");
with
if(blah...)
token = constStrings::coloncolon;
in an inner loop. If you call the above a few hundred thousand times, then it is very noticeable.
EDIT: This is actually not due to using a macro, but due to the fact that you pass a const char* rather than a wxString. But the evil thing is that you don't know that. The macro does not show it.
Regarding header protection, macros are the only thing I know of (short of #pragma which is even more evil). But I guess this is a legitimate use of macros.
thomas:
--- Quote from: 280Z28 on December 13, 2005, 02:26:55 am ---I only mentioned it because when I did a search in files for g_EditorManager, I did not see an immediate place where it was always initialized. If it was initialized at the declaration it would have saved me a bit of time because there would be no doubt.
--- End quote ---
It is a hack for MSVC++ to cope with the manager singletons.
But... you can't compile Code::Blocks with VC++ anyway, so it is pretty useless alltogether.
You can compile without that file alltogether, the compiler does not even give a warning (I just tried).
takeshimiya:
Well, the #define DEFAULT_BATCH_BUILD_ARGS example was obtained from C::B src/associations.h, so I can deduce the autor was born before 1977 :P
As for header protection, there isn't any compiler flag to tell the compiler "prevent multiple header inclusion please"?
Because sometimes the macro choosed clashes with another code, like #define MAIN_H or #define UTILS_H which are pretty common name of headers.
And also I sometimes forget to write the header protection.
And there is any way to not use macros in cases of compile time options (like #ifdef USE_UNICODE and such)?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version