By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

Preprocessor concatination of defines

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a
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.
Jul 22 '05 #3

P: n/a
JKop <NU**@NULL.NULL> wrote in message news:<EH*****************@news.indigo.ie>...
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!
Jul 22 '05 #4

P: n/a
On Thu, 01 Jul 2004 15:01:56 GMT, JKop <NU**@NULL.NULL> 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/~a...FAQ-acllc.html
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.