RE: [Dev-C++] is the preprocessor considered harmful?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Pierre R. <pie...@wa...> - 2003-04-25 20:26:14
|
"jp" <rar...@xt...> on Fri, 25 Apr 2003 07:27:16 +1200 wrote:
> Hi,
>=20
> This isn't a Dev-Cpp question, but I'd be interested in anyone's=20
> thoughts...
>=20
> If I'm using C++, I avoid using the preprocessor for anything except
> #include's and #pragma's.
>=20
> The directives I most despise are #line, as suffered by users of =
lex/yacc,
> esql, and other source code generators, and ...
>=20
> #ifdef ENTIRELY_STUPID_FEATURE_FOR_ANNOYING_CLIENT
> void stupid();
> #endif
>=20
> If I need a constant I use, eg, enum{SOMETHING=3D0xffffffff}; One of =
the
> benefits is that such constants are scoped. It bugs me when I want, =
eg,
> enum{ERROR=3D0xffffffff}; and ERROR has already been #defined in a =
header...
> Sometimes, wash my mouth out, I #undef, eg, ERROR..
>=20
> If I need a macro I use...
> template <typename someT> void xargle( someT& thing)
> {
> xargle_buffer << thing;
> }
>=20
> 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=20
> 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..
>=20
> DECLTYPE(int, INTEGER, Integer)
>=20
> the macro DECLTYPE looks like this...
>=20
> #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);
>=20
> and there is an equally brief IMPLTYPE.
> The library allows constructions like..
>=20
> Object thing =3D String("gimme five: ");
> String s =3D thing;
> Integer i =3D 4;
> thing =3D i;
>=20
> refInteger(thing)++;
> cout << s << thing;
>=20
> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> This all works pretty well, and my lisp handles multimedia, ISAM, COM,
> sockets and other exotica in a fully object oriented, but=20
> 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?
>=20
> Cheers,
> jp.
I'm not sure to fully understand your need, but may be you can get some =
ideas here:
Chap. 3 "Typelists", Modern C++ Design, Andrei Alexandrescu, Addison =
Wesley ed.
or else:
http://www.cuj.com/experts/2002/alexandr.htm?topic=3Dexperts
http://www.research.ibm.com/designpatterns/pubs/ph-jun00.pdf
with the loki library here:
http://sourceforge.net/projects/loki-lib/
Regards
Pierre Raoul
|