This is the mail archive of the
mailing list for the GCC project.
Re: a nifty feature for c preprocessor
- From: David Brown <david dot brown at hesbynett dot no>
- To: R A <ren_zokuken01 at hotmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 01 Jan 2012 13:58:10 +0100
- Subject: Re: a nifty feature for c preprocessor
- References: <BLU163-W342C12D3ED2E4138C6E37383AE0@phx.gbl>,<BLU163-W112D62C836C94E7A8E14BE83AE0@phx.gbl>,<BLU163-W101189B8A57201E7156C4B83AC0@phx.gbl>,<BLU163-W25C240E42C4F005C6EC8D483AC0@phx.gbl>,<4EFAE808.email@example.com>,<BLU163-W303D03E552FD7FE2F570BE83AC0@phx.gbl>,<4EFB9A8E.firstname.lastname@example.org>,<BLU163-W5AFB44552B05762B858C183AC0@phx.gbl>,<4EFC39E0.email@example.com>,<BLU163-W33EF3A335E22C77A2F06F883AD0@phx.gbl>,<20111229213714.3BFED33C83@vlsi1.gnat.com>,<BLU163-W10EEE0C95722F5A6ED284083AD0@phx.gbl>,<20111229231852.16ABB33C83@vlsi1.gnat.com> <BLU163-W631C380362A632A3AD381C83930@phx.gbl>
On 31/12/11 10:44, R A wrote:
alright, here's another example why eval is a good idea:
#define A 17 #define B 153 #define N1
((A + B)/2) /* intended was (17 + 153)/2 */
#undef A #define A 230 #define N2 ((A + B)/2) /*
intended was (230 + 153)/2 */
printf("%u %u", N1, N2);
sure, you can assign N1 to a static const, say N1_var, then invoke
that in when printf is finally called. or simply print N1, then after
the undef print N2. but what if we have to use both N1 and N2 in the
same conditional expression?? everybody should be aware by now that
there's a lot of ugly dependencies in cpp.
The best idea for something like this would be to use a static const (I
don't know why you dismissed that). Undefining and redefining your
macros like this is almost always a bad idea - it is far easier to
understand your program, and to write correct code, if macros mean one
thing and one thing only.
but for a *fairly complex*(1) conditional directives, spanning
several files, you have to call the macros all at the same time and
not one one-by-one. to get around it (if possible) is to employ an
even more complex system of defs and conditionals... or you can use
external scripts to generate the codes. but like i said, these could
just be small snippets of codes, where having scripts is
un-minimalistic. eval takes away all the ugliness.
(1) by fairly complex, i mean one that doesn't really merit a
script/macro processors to be written.
alright, if i can't convince the developers, would a maintainer (or
anybody that knosw their way around libcpp) please help me out on how
to get started my port for the feature... i actually don't like the
idea of writing a plugin.