473,769 Members | 5,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preprocessor concatination of defines

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,PR OJ_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,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,)
3. Lib3 version header is included:

#define PROJ_NAME "Lib3"
#define PROJ_VERSION 865

#define DEP_PROJECTS DEP_PROJECTS,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,"Lib3",8 65,)

But can it be done somehow?

Best regards Jakob
Jul 22 '05 #1
4 1698
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,PR OJ_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,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,)
3. Lib3 version header is included:

#define PROJ_NAME "Lib3"
#define PROJ_VERSION 865

#define DEP_PROJECTS DEP_PROJECTS,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,"Lib3",8 65,)

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
Jakob Simon-Gaarde wrote:
....

#define DEP_PROJECTS DEP_PROJECTS,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,"Lib3",8 65,)

But can it be done somehow?


No. Perhaps using m4, but not the standard CPP.
Jul 22 '05 #3
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,PR OJ_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,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,)
3. Lib3 version header is included:

#define PROJ_NAME "Lib3"
#define PROJ_VERSION 865

#define DEP_PROJECTS DEP_PROJECTS,PR OJ_NAME PROJ_VERSION,

(DEP_PROJECTS = "Lib1",102,"Lib 2",422,"Lib3",8 65,)

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_dependancie s()
{
return DEP_PROJECTS;
}

also pseudo!
Jul 22 '05 #4
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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1511
by: Pelle Beckman | last post by:
Hi, This might be OT... Are there preprocessor defines in the C++ standard, such as __FILE__, __LINE__, __NAMESPACE__, __FUNCTION__, ec? If there is, were can I find a list? If there isn't, does anyone know of a good list for those defines under Gcc (3.4 <=)?
13
2136
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int defined = 2;
9
6581
by: ccwork | last post by:
Hi all, We can define some magic number with #define: #define OPERATION_1 0x00000001 #define OPERATION_2 0x00000002 #define OPERATION_3 0x00000003 .... We can also do that with enum: enum OPERATION
3
13610
by: CPA Study Group | last post by:
Is it possible to write a C Preprocessor macro which changes the case of a string. This will save me time by not having to use awk of write my own preprocessor. Here is a sample code which I want to work --------- #ifdef LOWER #define NORMAL(x) MKLOWER(x) #else #define NORMAL(x) MKUPPER(x) #endif
5
2473
by: tb2000 | last post by:
Here's my scenario: VS2005, .NET and .NETCF C# projects mices in a single solution file, referencing the same source code base (the NETCF projects use reflinks to the NET sources) Now I am trying the following #if !NETCF {some code which is only compileable under .NET but now is excluded} #endif NETCF is defined in compiler settings
8
2879
by: s7master | last post by:
Is there any way I can check to see what agriculture (x86_64, ppc, ia32, etc) I am compiling with using the preprocessor? All help is appreciated.
31
2931
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
3
303
by: Nathan Moinvaziri | last post by:
I am wonder if there is a way to use preprocessor definitions to expose code only if a particular file is included in a project. I am targeting the msvc. I am thinking of something like #if defined(filecabinet.h) // if filecabinet.h is part of the project ....
14
2599
by: lagman | last post by:
All, I'm looking for a tool that is able to take my code base (which is full of preprocessor directives) and spit out source code that is "clean" of any preprocessor directives based on the options I choose (possibly via some kind of user input screen). Does such a tool exist? A Visual Studio plugin would be even better. FYI: I have requirements to rid my code of all conditionally compiled
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.