Preprocessor concatination of defines

Discussion in 'C++' started by Jakob Simon-Gaarde, Jul 1, 2004.

  1. Some project includes files from different libraries lib1,lib2 and
    lib3 all having each there own version header file. I need to be able
    to pick up these values in a single define value DEP_PROJECT. pseudo
    preprocessor code would look like this:

    1. Lib1 version header is included:

    #define PROJ_NAME "Lib1"
    #define PROJ_VERSION 102

    #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,

    (DEP_PROJECTS = "Lib1",102,)


    2. Lib2 version header is included:

    #define PROJ_NAME "Lib2"
    #define PROJ_VERSION 422

    #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,

    (DEP_PROJECTS = "Lib1",102,"Lib2",422,)


    3. Lib3 version header is included:

    #define PROJ_NAME "Lib3"
    #define PROJ_VERSION 865

    #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,

    (DEP_PROJECTS = "Lib1",102,"Lib2",422,"Lib3",865,)

    But can it be done somehow?

    Best regards Jakob
    Jakob Simon-Gaarde, Jul 1, 2004
    #1
    1. Advertising

  2. Jakob Simon-Gaarde

    JKop Guest

    Jakob Simon-Gaarde posted:

    > Some project includes files from different libraries lib1,lib2 and
    > lib3 all having each there own version header file. I need to be able
    > to pick up these values in a single define value DEP_PROJECT. pseudo
    > preprocessor code would look like this:
    >
    > 1. Lib1 version header is included:
    >
    > #define PROJ_NAME "Lib1"
    > #define PROJ_VERSION 102
    >
    > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    >
    > (DEP_PROJECTS = "Lib1",102,)
    >
    >
    > 2. Lib2 version header is included:
    >
    > #define PROJ_NAME "Lib2"
    > #define PROJ_VERSION 422
    >
    > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    >
    > (DEP_PROJECTS = "Lib1",102,"Lib2",422,)
    >
    >
    > 3. Lib3 version header is included:
    >
    > #define PROJ_NAME "Lib3"
    > #define PROJ_VERSION 865
    >
    > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    >
    > (DEP_PROJECTS = "Lib1",102,"Lib2",422,"Lib3",865,)
    >
    > But can it be done somehow?
    >
    > Best regards Jakob


    Well firstly you can't have two macros with the same name... well you can,
    but the second one just overwrites the first one, eg:

    #define a 1

    #define a 2

    a == 2 now.

    I'm going to assume that you've considering giving the macros different
    names and for some reason didn't go with it. I suggest the following for
    each included header file:

    namespace Lib1 {

    const char* const project_name = "Library1";
    const char* const project_version = "102";
    }


    and then for your second header file:

    namespace Lib2 {

    const char* const project_name = "Library2";
    ....
    ....
    ... and so on.


    -JKop
    JKop, Jul 1, 2004
    #2
    1. Advertising

  3. Jakob Simon-Gaarde wrote:
    ....
    >
    > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    >
    > (DEP_PROJECTS = "Lib1",102,"Lib2",422,"Lib3",865,)
    >
    > But can it be done somehow?


    No. Perhaps using m4, but not the standard CPP.
    Gianni Mariani, Jul 1, 2004
    #3
  4. JKop <> wrote in message news:<EHVEc.3634$>...
    > Jakob Simon-Gaarde posted:
    >
    > > Some project includes files from different libraries lib1,lib2 and


    > > lib3 all having each there own version header file. I need to be able
    > > to pick up these values in a single define value DEP_PROJECT. pseudo
    > > preprocessor code would look like this:
    > >
    > > 1. Lib1 version header is included:
    > >
    > > #define PROJ_NAME "Lib1"
    > > #define PROJ_VERSION 102
    > >
    > > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    > >
    > > (DEP_PROJECTS = "Lib1",102,)
    > >
    > >
    > > 2. Lib2 version header is included:
    > >
    > > #define PROJ_NAME "Lib2"
    > > #define PROJ_VERSION 422
    > >
    > > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    > >
    > > (DEP_PROJECTS = "Lib1",102,"Lib2",422,)
    > >
    > >
    > > 3. Lib3 version header is included:
    > >
    > > #define PROJ_NAME "Lib3"
    > > #define PROJ_VERSION 865
    > >
    > > #define DEP_PROJECTS DEP_PROJECTS,PROJ_NAME PROJ_VERSION,
    > >
    > > (DEP_PROJECTS = "Lib1",102,"Lib2",422,"Lib3",865,)
    > >
    > > But can it be done somehow?
    > >
    > > Best regards Jakob

    >
    > Well firstly you can't have two macros with the same name... well you can,
    > but the second one just overwrites the first one, eg:
    >
    > #define a 1
    >
    > #define a 2
    >
    > a == 2 now.
    >
    > I'm going to assume that you've considering giving the macros different
    > names and for some reason didn't go with it. I suggest the following for
    > each included header file:
    >
    > namespace Lib1 {
    >
    > const char* const project_name = "Library1";
    > const char* const project_version = "102";
    > }
    >
    >
    > and then for your second header file:
    >
    > namespace Lib2 {
    >
    > const char* const project_name = "Library2";
    > ...
    > ...
    > .. and so on.
    >
    >
    > -JKop


    The preprocessor code was pseudo-preprocessor code. But it explaines
    the problem. I am seeking an automatic dependancy information
    generator, so that as the version headerfiles are included a
    preprocessor define is build up. This way the I can store the version
    dependancy at the buildtime. whith a function like:

    std::string get_dependancies()
    {
    return DEP_PROJECTS;
    }

    also pseudo!
    Jakob Simon-Gaarde, Jul 1, 2004
    #4
  5. Jakob Simon-Gaarde

    Jack Klein Guest

    On Thu, 01 Jul 2004 15:01:56 GMT, JKop <> wrote in
    comp.lang.c++:

    > Jakob Simon-Gaarde posted:
    >
    > > Some project includes files from different libraries lib1,lib2 and
    > > lib3 all having each there own version header file. I need to be able
    > > to pick up these values in a single define value DEP_PROJECT. pseudo
    > > preprocessor code would look like this:


    [snip]

    > Well firstly you can't have two macros with the same name... well you can,
    > but the second one just overwrites the first one, eg:
    >
    > #define a 1
    >
    > #define a 2


    You can't do this in a program without making it ill-formed. A
    diagnostic is required. See paragraphs 1, 2, and 3 of section "16.3
    Macro replacement" in the C++ standard.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jul 2, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    453
    Thomas Matthews
    Feb 19, 2004
  2. Pelle Beckman

    Preprocessor defines

    Pelle Beckman, Jul 2, 2005, in forum: C++
    Replies:
    2
    Views:
    322
    Alan Johnson
    Jul 2, 2005
  3. Replies:
    9
    Views:
    373
  4. JChG
    Replies:
    1
    Views:
    238
    Steven D'Aprano
    Apr 19, 2010
  5. Noah Roberts
    Replies:
    5
    Views:
    734
    James Kanze
    Jan 12, 2011
Loading...

Share This Page