# in macro

J

junjiec

Hi,
Please tell me how could I have a #$B!J(Bsharp sign) expanded in the
macro such as
#define INCLUDE(filename) #include <filename>
which could do the expand below to include a file
INCLUDE(stdio.h) => #include <stdio.h>

Thank you in advance!
 
P

Peter Nilsson

[You've given us the solution that you're trying to implement,
but you haven't told what problem you're trying to solve.]

Hi,
Please tell me how could I have a #$B!J(Bsharp sign) expanded in the
macro such as
#define INCLUDE(filename) #include <filename>
which could do the expand below to include a file
INCLUDE(stdio.h) => #include <stdio.h>

You can't, but you can do things like...

#INCLUDE(X) <X>
#include INCLUDE(stdio.h)
 
J

junjiec

Thansk for your advice.
I am just tyring to implement a API Framework Specification which
requires the INCLUDE macro to be defined.

[You've given us the solution that you're trying to implement,
but you haven't told what problem you're trying to solve.]

Hi,
Please tell me how could I have a #$B!J(Bsharp sign) expanded in the
macro such as
#define INCLUDE(filename) #include <filename>
which could do the expand below to include a file
INCLUDE(stdio.h) => #include <stdio.h>

You can't, but you can do things like...

#INCLUDE(X) <X>
#include INCLUDE(stdio.h)
 
Q

quarkLore

Thansk for your advice.
I am just tyring to implement a API Framework Specification which
requires the INCLUDE macro to be defined.

[You've given us the solution that you're trying to implement,
but you haven't told what problem you're trying to solve.]

As mentioned in K&R Reference Manual the definition of macro (Section
A12.3) is
# define identifier token-sequence
Definition of token (section A2.1) says tokens have six classes:
identifiers, keywords,constants,string literals,
operators and other separators
# wont be in any of these.
I tried using trigraphs but the same problem occurs.
You can't, but you can do things like...
#INCLUDE(X) <X>
#include INCLUDE(stdio.h)
 
E

Eric Sosman

Hi,
Please tell me how could I have a #$B!J(Bsharp sign) expanded in the
macro such as
#define INCLUDE(filename) #include <filename>
which could do the expand below to include a file
INCLUDE(stdio.h) => #include <stdio.h>

C's preprocessor will not do this: macro expansion cannot
generate a preprocessor directive, even if the expansion happens
to resemble one.

If you really must have this effect, you'll need to run
your "C-ish" source through some other preprocessing program
before feeding it to a C compiler.
 
J

John Bode

Hi,
Please tell me how could I have a #$B!J(Bsharp sign) expanded in the
macro such as
#define INCLUDE(filename) #include <filename>
which could do the expand below to include a file
INCLUDE(stdio.h) => #include <stdio.h>

Thank you in advance!

You can't define a macro that expands into a preprocessor directive
and have it be recognized as such. All preprocessor directives are
processed before any macro expansion takes place.

If you want to parameterize include files, you'll have to use some
other method.
 
D

Dave Hansen

Thansk for your advice.
I am just tyring to implement a API Framework Specification which
requires the INCLUDE macro to be defined.
[...]

As other have said, can't be done.

You _can_ do something like this:

#if SYSTEM_TYPE == 3
#define SYSTEM_HEADER "system_3.h"
#else
#define SYSTEM_HEADER "system_default.h"
#endif
...
#include SYSTEM_HEADER

But I'm not sure that helps.

Regards,
-=Dave
 
P

Peter Nilsson

quarkLore said:
As mentioned in K&R Reference Manual the definition of macro (Section
A12.3) is
# define identifier token-sequence
Definition of token (section A2.1) says tokens have six classes:
identifiers, keywords,constants,string literals,
operators and other separators
# wont be in any of these.

Which suggests either the reference manual has an error, or you are
misreading it.

N1124 distinguishes between preprocessing tokens and tokens:

preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
each non-white-space character that cannot be one of the above

In particular, # and ## are punctuators.
I tried using trigraphs but the same problem occurs.

That's because they are removed in translation phase 1, whereas
preprocessing
directives aren't processed until translation phase 4.
 
P

Peter Nilsson

[Please don't top-post.]
Peter Nilsson said:
[You've given us the solution that you're trying to
implement, but you haven't told what problem you're
trying to solve.]
<snip>

Thansk for your advice.
I am just tyring to implement a API Framework Specification which
requires the INCLUDE macro to be defined.

You have a problem, let's call it X.
You think the solution is Z, but you can't get Z to work.
Without telling us what X is, you ask us how to fix Z.
We tell you that you can't do Z and ask what X is.
You still don't tell us what X is, only that X requires Z.

In other words, you're still just telling me that you have a problem
without
telling me what the problem is.

Why does this so-called API Framework require you to define an INCLUDE
macro? What _problem_ is the INCLUDE macro supposed to solve?
What situation are you faced with that can't be solved using the
normal
conditional inclusion methods?

Samples would be nice. We don't need 10000 pages of specification,
just
the task at hand.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top