Advertisement

11.16.2006 at 03:46PM PST, ID: 22063830
[x]
Attachment Details

c++ preprocess directives

Asked by ADSLMark in C++ Programming Language

Tags: __base__, tostr

Hello,

I was trying to use #define directives to make a base directory for all my include files. So the idea was:

Compile the program with a flag -D__BASE__=/some/path/to/base/ and then add this before the filename in the #include.
So basically:

#include __BASE__ "Foo.h"

This does not work (of course), but I searched the internet and found some information about directives and I came up with this:

#define CONCAT(a, b) a b
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define ROOT TOSTRING(__BASE__)
#include CONCAT(ROOT, "Foo.h")

But this does not work either. I think the problem lies in the fact that I do not precisely know how this is processed (although it looks very simple), anyway there are 'tokens' and 'strings' and it just seems I cannot concat two strings.
For example I get things like

"/some/path/" "Foo.h"

or sometimes I even get /some/path/Foo.h, but when using it on the #include it says: /some/path/: No such file or directory, in other words, it only took the first part. So I guess the preprocessor just replaces everything and does not really DO anything.

Anyway, any help would be appreciated. Thank you.

Mark

Start Free Trial
 
Loading Advertisement...
 
[+][-]11.16.2006 at 04:03PM PST, ID: 17961522

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: __base__, tostr
Sign Up Now!
Solution Provided By: grg99
Participating Experts: 3
Solution Grade: C
 
 
[+][-]11.17.2006 at 01:28AM PST, ID: 17963634

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 02:02AM PST, ID: 17963733

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 06:54AM PST, ID: 17965470

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 10:12AM PST, ID: 17967282

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 10:13AM PST, ID: 17967287

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 10:43AM PST, ID: 17967540

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 10:58AM PST, ID: 17967691

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 11:03AM PST, ID: 17967730

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.17.2006 at 10:15PM PST, ID: 17970586

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.18.2006 at 01:22AM PST, ID: 17970884

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.18.2006 at 03:38PM PST, ID: 17972922

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32