Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Link time info gathering

Link time info gathering

Scheduled Pinned Locked Moved Managed C++/CLI
c++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rostfrei
    wrote on last edited by
    #1

    Hello! I wonder if there is some way or some trick to gather some info during compile time and using it at runtime ? example1: We have many cpp files. We have some #define CPP_COUNTER 0. There would be some code (macro?) at the begining of every cpp file which would increase this counter for 1. When linking the project, CPP_COUNTER would hold the number of cpp files. In runtime I would be aware of cpp files in the project by reading CPP_COUNTER definition. example2: We have many files in the project, but functionaly they are divided in few modules (dsp, writter, reader, etc). At compile time every cpp file would have at the begining some code which would register (to some global variable) to which module it belongs. Something like REGISTER_MODULE(_FILENAME_, "disk writter") In runtime I would be aware of all the modules in the system by looking at the global variable of all registered modules. I would need something like example2 shows. Is it even possible? Is there some way? Best regards, Rostfrei

    R 1 Reply Last reply
    0
    • R Rostfrei

      Hello! I wonder if there is some way or some trick to gather some info during compile time and using it at runtime ? example1: We have many cpp files. We have some #define CPP_COUNTER 0. There would be some code (macro?) at the begining of every cpp file which would increase this counter for 1. When linking the project, CPP_COUNTER would hold the number of cpp files. In runtime I would be aware of cpp files in the project by reading CPP_COUNTER definition. example2: We have many files in the project, but functionaly they are divided in few modules (dsp, writter, reader, etc). At compile time every cpp file would have at the begining some code which would register (to some global variable) to which module it belongs. Something like REGISTER_MODULE(_FILENAME_, "disk writter") In runtime I would be aware of all the modules in the system by looking at the global variable of all registered modules. I would need something like example2 shows. Is it even possible? Is there some way? Best regards, Rostfrei

      R Offline
      R Offline
      RichardS
      wrote on last edited by
      #2

      Hi Rostfrei, One way of doing this is to create a dummy counting class and just create instances of it. Hence this becomes:

      countcpp.h:
      #ifndef __COUNT_H__
      #define __COUNT_H__

      #include <iostream.h>

      #define REGISTER_MODULE(file,des) static CCountCpp g_cppFile (file, des);

      class CCountCpp
      {
      public:
      CCountCpp (void) { }

      CCountCpp (const char *strFile, const char *strDes)
      {
      cout << strFile << "{ " << strDes << " }" << endl;
      ++m_iCppCount;
      }

      static int m_iCppCount;
      };

      #endif // __COUNT_H__

      This just creates a static CCountCpp object per REGISTER_MODULE define. Because of the static objects they can be the same name across modules as long as you are not including .cpp files. To use:

      #include "countcpp.h"

      REGISTER_MODULE(__FILE__, "disk writer");

      int CCountCpp::m_iCppCount = 0;

      void main (void)
      {
      CCountCpp c;
      cout << "Cpp count: " << c.m_iCppCount << endl;
      }

      Naturally you would remove the main, it is just there for show. regards, Rich "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups