Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 955073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:19:14+00:00 2026-05-16T00:19:14+00:00

Here’s the scenario. We use Visual C++ 9. There’s a C++ library intended to

  • 0

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

#pragma once

//CommonLibraryHeader.h
CSomeClass GetSomeClassFunction(); //is defined in some .cpp file
const CSomeClass MagicValue( 100, 200 ); //some predefined value that the previous function retuns to signify something important

now the library is built into a .dll file. The header file is published in a common location and included into several other libraries. Those libraries are built into their .dll files.

The net result is the following. Since every .dll is a separate executable module it has to preserve all those constants. Each “constant” is in fact an instance of a class with a non-trivial constructor and destructor. Now every .dll has a copy of MagicValue and code for construction and destruction of the variable is injected into every .dll file which adds to the load time and inflates the .dll files considerably if the same happens for many constants.

The possible solution is to mark the constant extern and move the definition into a .cpp file. But then the constant values passed into the constructor are not immediately visible to the human reader of the header file. One could add a comment there about what the values are but as usual now we would heve to keep the comment in sync with the actual code.

Is there any better solution – without moving the constants from the header and without injecting the construction/destruction code into every .dll file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:19:14+00:00Added an answer on May 16, 2026 at 12:19 am

    You could use the trick that is often used with DLL’s that export classes and functions: use a #define that is defined only when the DLL you want to include the code in is built, but not defined in the others, and do an #if that either calls the constructor or defines it as extern, as appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes
Here is a scenario: User installs .NET application that you have made. After some
Here's a sample of a SpinBox that writes its changes to underlying variables. The
here are 2 screen shots when i try to debug my code in visual
Here a simple question : What do you think of code which use try
Here's what I'm trying to do... It's quite simple and obviously there must be
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
here is the scenario 1: user starts to type some word, autocomplete engine shows
Here an example http://jsfiddle.net/EhLsT/ $(window).scroll(function () { if ($(window).scrollTop() > $(#header).offset().top) { $(#floating).show(); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.