[Dev-C++] is the preprocessor considered harmful?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: jp <rar...@xt...> - 2003-04-24 19:24:31
|
Hi,
This isn't a Dev-Cpp question, but I'd be interested in anyone's thoughts...
If I'm using C++, I avoid using the preprocessor for anything except
#include's and #pragma's.
The directives I most despise are #line, as suffered by users of lex/yacc,
esql, and other source code generators, and ...
#ifdef ENTIRELY_STUPID_FEATURE_FOR_ANNOYING_CLIENT
void stupid();
#endif
If I need a constant I use, eg, enum{SOMETHING=0xffffffff}; One of the
benefits is that such constants are scoped. It bugs me when I want, eg,
enum{ERROR=0xffffffff}; and ERROR has already been #defined in a header...
Sometimes, wash my mouth out, I #undef, eg, ERROR..
If I need a macro I use...
template <typename someT> void xargle( someT& thing)
{
xargle_buffer << thing;
}
BUT, and here's the point of my question, I don't know of any way to
stringize or token paste without using the preprocessor. I have a lisp. Not
literally, like thith, but a library I've written. Built in types are
instantiated using templates, so that, given a constant type id (eg:
INTEGER), I can add a new type like so..
DECLTYPE(int, INTEGER, Integer)
the macro DECLTYPE looks like this...
#define DECLTYPE(T, I, n)typedef imp::ImplObject<T, I> n;\
bool is##n(const Object &obj);\
const T &get##n(const Object &obj);\
T &ref##n(const Object &obj);
and there is an equally brief IMPLTYPE.
The library allows constructions like..
Object thing = String("gimme five: ");
String s = thing;
Integer i = 4;
thing = i;
refInteger(thing)++;
cout << s << thing;
==========================================
This all works pretty well, and my lisp handles multimedia, ISAM, COM,
sockets and other exotica in a fully object oriented, but typesafe, manner.
But FUNGLTYPE is a macro, and like I say, #define's are for grannies, so..
..does anybody know of an alternative to macros for generating identifiers
from user supplied fragments?
Cheers,
jp.
|