On Mon, Nov 16, 2009 at 9:38 AM, Marvin Humphrey <[email protected]> wrote: > #include <stdio.h> > > #define QUOTE(x) #x "\n" > > const char code[] = QUOTE(\ > #include <stdio.h>\n > int main() { > printf("Greetings, Earthlings!\n"); > return 0; > } > ); > > int main() { > printf("%s", code); > return 0; > } > > I think our best bet is to go with real string literals and manual escaping. > IMO, there are too many limitations, quirks and gotchas to make preprocessor > stringification worthwhile.
I understand this reasoning, but I guess I'd go with the QUOTE macro unless there prove to be more known quirks. Right now, we are at: 1) First line starts with a '\' or the code itself. 2) Include is spelled '#include <header.h>\n\' (with last slash) 3) No comma operator or multiple variable declarations. 4) Unknown support beyond GCC and MSVC. What we gain is crystal clear code, no outside dependencies, and an otherwise markup free syntax that an editor can automatically indent and highlight. I question the benefit of trying to support 'all C89 compilers'. Don't reinvent autoconf --- either use it, or do something simple and lightweight that accomplishes your immediate goal. Yes, you'll run into bugs with odd compilers, but pragmatically, the only reason I can see for supporting that odd compiler is to gain the support of the contributing programmer who wants to use it. How likely is this, and what compiler would this be? I'd go with whatever is going to be easiest to maintain, even if this means limiting your target audience to the 98% of compilers in regular use. Oddly, the easiest way of being easy to maintain might be to have a low but solid barrier against obsolete and obscure compilers. Personally, I even think supporting MSVC is of dubious benefit unless you need it yourself. > Are we on the same page? I'm fine either way. I think both QUOTE() and manual are better than METAQUOTE. Nathan Kurz [email protected]
