Question about many #define

A

Alan Pong

#define PIC1 "pic1.gif"
#define PIC2 "pic2.gif"
:
:
#define PIC999 "pic999.gif"

any shortcut/trick/preprocessor directive/operator can do above easily?

thanks.
rgds.
alan
--END
 
O

Owen Jacobson

#define PIC1 "pic1.gif"
#define PIC2 "pic2.gif"
:
:
#define PIC999 "pic999.gif"

any shortcut/trick/preprocessor directive/operator can do above easily?

What are you really trying to do? What is the problem the above is
attempting to solve?

// Untested, and my macro-fu is seriously weak
#define PIC(x) "pic" #x ".gif"

// Unsure of efficiency of ostringstream, but otherwise better, IMO
#include <string>
#include <sstream>

inline
std::string pic(int x) {
std::eek:stringstream buffer;
buffer << "pic" << x << ".gif";
return buffer.str ();
}
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Alan said:
#define PIC1 "pic1.gif"
#define PIC2 "pic2.gif"
:
:
#define PIC999 "pic999.gif"

any shortcut/trick/preprocessor directive/operator can do above easily?

Write a program that write it.

But I wonder why you need to do that.
 
G

Greg Comeau

#define PIC1 "pic1.gif"
#define PIC2 "pic2.gif"
:
:
#define PIC999 "pic999.gif"

any shortcut/trick/preprocessor directive/operator can do above easily?

You can probably ease it with the preprocessor string'izing operator
(google that) but this leads to the question of "What are you trying
to ease?" That is, why do you need so many define's? How is
it better than just keeping track of some int? Etc.
 

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
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top