Connecting Tech Pros Worldwide Forums | Help | Site Map

Preprocessor concatination of defines

Jakob Simon-Gaarde
Guest
 
Posts: n/a
#1: Jul 22 '05
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

JKop
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Preprocessor concatination of defines


Jakob Simon-Gaarde posted:
[color=blue]
> 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[/color]

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
Gianni Mariani
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Preprocessor concatination of defines


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

No. Perhaps using m4, but not the standard CPP.
Jakob Simon-Gaarde
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Preprocessor concatination of defines


JKop <NULL@NULL.NULL> wrote in message news:<EHVEc.3634$Z14.4382@news.indigo.ie>...[color=blue]
> Jakob Simon-Gaarde posted:
>[color=green]
> > Some project includes files from different libraries lib1,lib2 and[/color][/color]
[color=blue][color=green]
> > 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[/color]
>
> 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[/color]

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!
Jack Klein
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Preprocessor concatination of defines


On Thu, 01 Jul 2004 15:01:56 GMT, JKop <NULL@NULL.NULL> wrote in
comp.lang.c++:
[color=blue]
> Jakob Simon-Gaarde posted:
>[color=green]
> > 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:[/color][/color]

[snip]
[color=blue]
> 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[/color]

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/~a...FAQ-acllc.html
Closed Thread


Similar C / C++ bytes