Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Preprocessing

Reply
Thread Tools

Preprocessing

 
 
R.Biloti
Guest
Posts: n/a
 
      07-19-2006
Hi folks

I would like to do something like

#define data_x1 data_x1_bbj
#define data_x2 data_x2_bbj
#define label_xy label_xy_bbj

Since the suffix bbj can change from time to time, I've tried

#define XX bbj

#define data_x1 data_x1_ ## XX
#define data_x2 data_x2_ ## XX
#define label_xy label_xy_ ## XX

but that doesn't produce what I'm willing, that is, XX doesn't get
replaced
by bbj in the three define's.

Any clue how to do that?

Regards,
Biloti

 
Reply With Quote
 
 
 
 
Mohan
Guest
Posts: n/a
 
      07-19-2006

R.Biloti wrote:
> Hi folks
>
> I would like to do something like
>
> #define data_x1 data_x1_bbj
> #define data_x2 data_x2_bbj
> #define label_xy label_xy_bbj
>
> Since the suffix bbj can change from time to time, I've tried
>
> #define XX bbj
>
> #define data_x1 data_x1_ ## XX
> #define data_x2 data_x2_ ## XX
> #define label_xy label_xy_ ## XX
>
> but that doesn't produce what I'm willing, that is, XX doesn't get
> replaced
> by bbj in the three define's.
>
> Any clue how to do that?


you may want to do it like this:

#define DATA_X1(a) data_x1 ## a
#define DATA_X2(a) data_x2 ## a
#define DATA_XY(a) data_xy ## a

and you can use it as - DATA_X1(bbj), DATA_X2(obj), etc

--Mohan

>
> Regards,
> Biloti


 
Reply With Quote
 
 
 
 
R.Biloti
Guest
Posts: n/a
 
      07-19-2006
Mohan escreveu:

> R.Biloti wrote:
> > Hi folks
> >
> > I would like to do something like
> >
> > #define data_x1 data_x1_bbj
> > #define data_x2 data_x2_bbj
> > #define label_xy label_xy_bbj
> >
> > Since the suffix bbj can change from time to time, I've tried
> >
> > #define XX bbj
> >
> > #define data_x1 data_x1_ ## XX
> > #define data_x2 data_x2_ ## XX
> > #define label_xy label_xy_ ## XX
> >
> > but that doesn't produce what I'm willing, that is, XX doesn't get
> > replaced
> > by bbj in the three define's.
> >
> > Any clue how to do that?

>
> you may want to do it like this:
>
> #define DATA_X1(a) data_x1 ## a
> #define DATA_X2(a) data_x2 ## a
> #define DATA_XY(a) data_xy ## a
>
> and you can use it as - DATA_X1(bbj), DATA_X2(obj), etc
>
> --Mohan


But that implies that I should type bbj wherever I use the macros
DATA_X1, DATA_X2, etc, and therefore, when I change bbj to kkt, I would
have to search-and-replace in the entire code, which is exactly what I
as trying to avoid.

Biloti

 
Reply With Quote
 
Allan M. Bruce
Guest
Posts: n/a
 
      07-19-2006

"R.Biloti" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
> Mohan escreveu:
>
>> R.Biloti wrote:
>> > Hi folks
>> >
>> > I would like to do something like
>> >
>> > #define data_x1 data_x1_bbj
>> > #define data_x2 data_x2_bbj
>> > #define label_xy label_xy_bbj
>> >
>> > Since the suffix bbj can change from time to time, I've tried
>> >
>> > #define XX bbj
>> >
>> > #define data_x1 data_x1_ ## XX
>> > #define data_x2 data_x2_ ## XX
>> > #define label_xy label_xy_ ## XX
>> >
>> > but that doesn't produce what I'm willing, that is, XX doesn't get
>> > replaced
>> > by bbj in the three define's.
>> >
>> > Any clue how to do that?

>>
>> you may want to do it like this:
>>
>> #define DATA_X1(a) data_x1 ## a
>> #define DATA_X2(a) data_x2 ## a
>> #define DATA_XY(a) data_xy ## a
>>
>> and you can use it as - DATA_X1(bbj), DATA_X2(obj), etc
>>
>> --Mohan

>
> But that implies that I should type bbj wherever I use the macros
> DATA_X1, DATA_X2, etc, and therefore, when I change bbj to kkt, I would
> have to search-and-replace in the entire code, which is exactly what I
> as trying to avoid.
>
> Biloti
>


or you could have another macro
#define SUFF bbj

and use DATA_X1(SUFF), DATA_X2(SUFF) then all you need to do is change the
define for SUFF to avoid searching through the whole code
Allan


 
Reply With Quote
 
Mohan
Guest
Posts: n/a
 
      07-19-2006

R.Biloti wrote:
> Mohan escreveu:
>
> > R.Biloti wrote:
> > > Hi folks
> > >
> > > I would like to do something like
> > >
> > > #define data_x1 data_x1_bbj
> > > #define data_x2 data_x2_bbj
> > > #define label_xy label_xy_bbj
> > >
> > > Since the suffix bbj can change from time to time, I've tried
> > >
> > > #define XX bbj
> > >
> > > #define data_x1 data_x1_ ## XX
> > > #define data_x2 data_x2_ ## XX
> > > #define label_xy label_xy_ ## XX
> > >
> > > but that doesn't produce what I'm willing, that is, XX doesn't get
> > > replaced
> > > by bbj in the three define's.
> > >
> > > Any clue how to do that?

> >
> > you may want to do it like this:
> >
> > #define DATA_X1(a) data_x1 ## a
> > #define DATA_X2(a) data_x2 ## a
> > #define DATA_XY(a) data_xy ## a
> >
> > and you can use it as - DATA_X1(bbj), DATA_X2(obj), etc
> >
> > --Mohan

>
> But that implies that I should type bbj wherever I use the macros
> DATA_X1, DATA_X2, etc, and therefore, when I change bbj to kkt, I would
> have to search-and-replace in the entire code, which is exactly what I
> as trying to avoid.


No, you need to have one more set of macros, like (can be placed in a
header file):
#define DATA_X1(a) data_x1 ## a
#define DDATA_X1 DATA_X1(obj)

#define DATA_X2(a) data_x2 ## a
#define DDATA_X2 DATA_X2(obj)

etc

the macros DDATA_* are used in the rest of the code, hence the changes
are centralized.

--Mohan
>
> Biloti


 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      07-19-2006
"R.Biloti" <(E-Mail Removed)> wrote:
# Hi folks
#
# I would like to do something like
#
# #define data_x1 data_x1_bbj
# #define data_x2 data_x2_bbj
# #define label_xy label_xy_bbj
#
# Since the suffix bbj can change from time to time, I've tried
#
# #define XX bbj
#
# #define data_x1 data_x1_ ## XX
# #define data_x2 data_x2_ ## XX
# #define label_xy label_xy_ ## XX
#
# but that doesn't produce what I'm willing, that is, XX doesn't get
# replaced
# by bbj in the three define's.
#
# Any clue how to do that?

You have to #define two levels down.

t.c:
#define data_x1 CONCAT(data_x1_,XX)
#define data_x2 CONCAT(data_x2_,XX)
#define label_xy CONCAT(label_xy_,XX)

#define XX bbj

#define CONCAT(a,b) CONCAT2(a,b)
#define CONCAT2(a,b) a##b

x1 = data_x1
x2 = data_x2
xy = label_xy

cc -E t.c
# 1 "t.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.c"
# 10 "t.c"
x1 = data_x1_bbj
x2 = data_x2_bbj
xy = label_xy_bbj



--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Summary: translation units, preprocessing, compiling and linking? Victor Bazarov C++ 0 05-09-2006 11:00 PM
Re: Summary: translation units, preprocessing, compiling and linking? Mark A. Gibbs C++ 0 05-09-2006 11:00 PM
Summary: translation units, preprocessing, compiling and linking? Steven T. Hatton C++ 7 06-03-2004 06:01 PM
Preprocessing directives Ron C++ 3 11-12-2003 04:45 AM
Indentation of preprocessing directives Dave C++ 2 11-03-2003 03:34 AM



Advertisments