473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

#define a macro that #includes

first of all: sorry for perhaps posting something already answered
anywhere, i couldnt find any useful info - define, macro, include and
so on are very poor keywords;-)

my problem:

i want to do something like...

INCLUDE_TYPES(#include);

....that resolves to ...

#include "file1.h"
#include "file2.h"
#include "file3.h"
.... and my try was a...

#define INCLUDE_TYPES(Q_L) \
Q_L "file1.h" \
Q_L "file2.h" \
Q_L "file3.h" \

....but my compiler complains about...

'#' : invalid character : possibly the result of a macro expansion

....so that way dont work. i cant do a simple...

#include "files.h"

....with all other includes in that file so im looking for some
different idea and would appreciate any useful help.

TIA, -.rhavin;-)
Apr 10 '08 #1
5 1692
jxh
On Apr 10, 10:41*am, ".rhavin grobert" <cl...@yahoo.dewrote:
>
my problem:

i want to do something like...

INCLUDE_TYPES(#include);

...that resolves to ...

#include "file1.h"
#include "file2.h"
#include "file3.h"

... and my try was a...

#define INCLUDE_TYPES(Q_L) \
Q_L "file1.h" \
Q_L "file2.h" \
Q_L "file3.h" \

...but my compiler complains about...

*'#' : invalid character : possibly the result of a macro
expansion

...so that way dont work.
Right. You can't expand a preprocessor macro into a
preprocessor directive. You can use the presence of
a macro to determine whether or not to include your
header files by:

#ifdef INCLUDE_TYPES
# include "file1.h"
# include "file2.h"
# include "file3.h"
#endif
i cant do a simple...

#include "files.h"

...with all other includes in that file so im looking for some
different idea and would appreciate any useful help.
You need to explain why you can't do that.

-- James
Apr 10 '08 #2
In article <5d**********************************@1g2000prg.go oglegroups.com>,
..rhavin grobert <cl***@yahoo.dewrote:
>my problem:
>i want to do something like...
>INCLUDE_TYPES(#include);
>...that resolves to ...
>#include "file1.h"
#include "file2.h"
#include "file3.h"
You cannot do that. No macro can expand to a preprocessor directive.
--
"Walter is a great man." -- Dennis Green
Apr 10 '08 #3
On Thu, 10 Apr 2008 10:41:30 -0700, .rhavin grobert wrote:
first of all: sorry for perhaps posting something already answered
anywhere, i couldnt find any useful info - define, macro, include and so
on are very poor keywords;-)

my problem:

i want to do something like...

INCLUDE_TYPES(#include);

...that resolves to ...

#include "file1.h"
#include "file2.h"
#include "file3.h"
That's not possible in C. Macro expansions cannot ever generate
preprocessing directives.
... and my try was a...

#define INCLUDE_TYPES(Q_L) \
Q_L "file1.h" \
Q_L "file2.h" \
Q_L "file3.h" \

...but my compiler complains about...

'#' : invalid character : possibly the result of a macro expansion
Right. Since #include doesn't appear at the start of a line in your code,
it's not a directive, and the # is left and causes syntax errors.
...so that way dont work. i cant do a simple...

#include "files.h"

...with all other includes in that file so im looking for some different
idea and would appreciate any useful help.
Why can't you do that? If you have a problem you want to solve, ask about
that problem. Your attempted solution doesn't work and can't be made to
work. Asking how to change that solution so that it will work won't get
you useful answers. Asking how to solve your original problem may.
Apr 10 '08 #4
".rhavin grobert" <cl***@yahoo.dewrites:
first of all: sorry for perhaps posting something already answered
anywhere, i couldnt find any useful info - define, macro, include and
so on are very poor keywords;-)

my problem:

i want to do something like...

INCLUDE_TYPES(#include);

...that resolves to ...

#include "file1.h"
#include "file2.h"
#include "file3.h"
... and my try was a...

#define INCLUDE_TYPES(Q_L) \
Q_L "file1.h" \
Q_L "file2.h" \
Q_L "file3.h" \

...but my compiler complains about...

'#' : invalid character : possibly the result of a macro expansion
The result of a macro expansion can't be a pre-processing directive --
no matter how much it looks like one. No macro can generate a
#include, #define etc. You can generate those tokens, but they are
not treated as directives.
...so that way dont work. i cant do a simple...

#include "files.h"

...with all other includes in that file so im looking for some
different idea and would appreciate any useful help.
Backup a bit. What problem were you trying to solve?

--
Ben.
Apr 10 '08 #5
rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
.rhavin grobert <cl...@yahoo.dewrote:
my problem:
i want to do something like...
INCLUDE_TYPES(#include);
...that resolves to ...
#include "file1.h"
#include "file2.h"
#include "file3.h"

No macro can expand to a preprocessor directive.
True, but preprocessing directives, including #include,
can expand to macros.

It's possible to do something like what the OP wants
(upto a static limit), but it's questionable as to
whether it's worth doing. Since the OP has admitted
to using C++, it's more likely there are better C++
paradigms to achieve what they really need to do.

But there is a Boost header that does many surprising
pre-processor tricks, and is both C and C++ compatible.

--
Peter
Apr 11 '08 #6

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

Similar topics

97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
5
by: Timothy Madden | last post by:
Hello If I say #define MASK 0x00F0 #define BIT_SET MASK #define MASK 0x000F than what value will BIT_SET macro expand to ? I mean the preprocessor does lasy evaluation or immediate...
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
13
by: marcwentink | last post by:
Dear people, The code below is compiling: #define BUF_SZ 16383 ..... strcat(ConnectString, "Content-Length: BUF_SZ\n"); but it does not work since it give me:
10
by: mohan | last post by:
Hi All. I have error message #include <stdio.h> #define NAV_FORMAT_VERSION 10 #define OC_LM_ANNOT 1
3
by: iler.ml | last post by:
I am writing code that uses two third-party libraries. They both define same macro OP_ENCRYPT, and luckily for me, they both define it to 0. (In one include, it's '#define OP_ENCRYPT 0', in...
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.