c++ - How do I keep a constant definition in a header file and not have it linked into every library? -


Here is the scenario that we use Visual C ++ 9. There is a C ++ library to be used by many other libraries. Its interface is in a header:

  Once #pragma / colonelarythider CSOM Class GetSomeClassFunction (); // some. The CPP file is defined in the CSOmclass Magic value (100, 200); // Some predefined values ​​that show the previous function some important  

, now the library. Dll file is built in. The header file has been published in a common location and is included in many other libraries. Those libraries have been built in their .dll files.

The net result is low as each .dll is a separate executable module, so it has to preserve all those constants. Each "continuous" is actually an example of a class with a non-trivial constructor and disaster. Now every .dL has a copy of MagicValue and the code for the creation and destruction of variables is injected into each .dll file which adds load time and. Dll greatly increases files if this is the case with multiple constants

It is possible that continuously mark extern and define the definition. Place in CPP file. But in the Constructor, the continuous constant value header file does not appear immediately to the human reader. Anyone can add a comment about the value, but in general we now want to keep the comment synchronized with the actual code.

Is there a better solution - do not move the constants ahead of the title and without injection of creation / destruction code in every .dll file?

You can use the trick that is often used with DLL's Export sections and functions : Use #define, which is defined only when you want to include the code, it has been created, but not defined in others, and it is a #if Either calls the constructor or defines it as an appropriate form of the extension .


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -