Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
static variables in cbplugin.h
ollydbg:
I just found a potential bug:
Here, in cbplugin.h, there are code like:
--- Code: ---// Define basic groups for plugins' configuration.
static const int cgCompiler = 0x01; ///< Compiler related.
static const int cgDebugger = 0x02; ///< Debugger related.
static const int cgEditor = 0x04; ///< Editor related.
static const int cgCorePlugin = 0x08; ///< One of the core plugins.
static const int cgContribPlugin = 0x10; ///< One of the contrib plugins (or any third-party plugin for that matter).
static const int cgUnknown = 0x20; ///< Unknown. This will be probably grouped with cgContribPlugin.
--- End code ---
This will let all the translation unit which include the "cbplugin.h" have a own copy of those variables. Is that a bug?
Why not just use extern modifier, and define them in the cpp files???
Or just use enum?
danselmi:
They are defined as const. So a "copy" is the same constant value.
Folco:
This is a linker optimisation, no ? "Constant merging". Is it guaranteed by the standard ?
ollydbg:
--- Quote from: danselmi on December 27, 2011, 12:03:06 pm ---They are defined as const. So a "copy" is the same constant value.
--- End quote ---
Yes. But...Anyway, I do believe variable definitions in header file is not a good idea.
MortenMacFly:
--- Quote from: ollydbg on December 27, 2011, 02:49:21 pm ---Yes. But...Anyway, I do believe variable definitions in header file is not a good idea.
--- End quote ---
static const can be seen as the c++ style of a #define. In the case you refer to it's also similar to an enum, so this is OK.
Navigation
[0] Message Index
[#] Next page
Go to full version