Preprocessor concatination of defines

  • Thread starter Jakob Simon-Gaarde
  • Start date
J

Jakob Simon-Gaarde

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
 
J

JKop

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
 
G

Gianni Mariani

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.
 
J

Jakob Simon-Gaarde

JKop said:
Jakob Simon-Gaarde posted:


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!
 
J

Jack Klein

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top