0

I need to have a content of one of header files at compile time. Is it possible using, for example, #define or constexpr under Visual Studio 2015?

P.S> To clarify, why I need that: I have some config files which looks like this:

<ModelSettingsData version="1.0" xmlns="ded" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Param name="lightOuterLanding[0]"  bus="L_ESS_DC"              load="200"/>
    <Param name="lightOuterLanding[1]"  bus="R_ESS_DC"              load="200"/>
    <Param name="lightOuterLanding[2]"  bus="TOWING_DC or APU_DC"   load="8"/>
    <Param name="lightOuterTaxi[0]"     bus="L_AC"                  load="92"/>
    <Param name="lightOuterTaxi[1]"     bus="R_AC"                  load="92"/>
    <Param name="lightOuterRwyOff[0]"   bus="L_AC"                  load="65"/>
    <Param name="lightOuterRwyOff[1]"   bus="R_AC"                  load="65"/>
</ModelSettingsData>

and the header file like this:

struct ElecLightPower {
    float lightOuterLanding[4];
    float lightOuterTaxi[2];
    float lightOuterRwyOff[2];
    // ...
};

I need to fill the structure from the header file with the data which is calculated using parameters from the config file. Now I read this header as text on the program init and do what I need (actually just count byte shifts for every parameter), but the problem comes when I update the header in source code, but forget to put updated version of that file in the folder with the binary. For that reason I just want somehow to get the content of .h file in my code, to not read it from the disk on runtime.

  • 2
    I dont understand what you mean by `have a content of one of header files at compile time`. Isn't the header file present on your hard drive, and therefore available at compile time? – Jeremy Friesner Sep 15 '22 at 05:32
  • 2
    What do you think normally happens when you `#include` a header file? – Nathan Pierson Sep 15 '22 at 05:33
  • 3
    **What are you really trying to do?** – selbie Sep 15 '22 at 05:48
  • It might be possible, but since you haven't really said what 'it' is it's not possible to say any more. – john Sep 15 '22 at 06:17
  • @JeremyFriesner Updated the header and put additional information in the question body –  Sep 15 '22 at 06:37
  • @selbie added `P.S>` part to question –  Sep 15 '22 at 06:38
  • 1
    You need to implement a code generation step before build that will read config and generate C++ source file with data. – user7860670 Sep 15 '22 at 07:14
  • Do you actually want to [include a file as a string literal](https://stackoverflow.com/questions/43256465/include-a-file-as-a-string)? – Jakob Stark Sep 15 '22 at 07:41
  • @JakobStark yes, I read these questions, but there is no solution for my case: Windows + file which can be compiled –  Sep 15 '22 at 08:03

0 Answers0