Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Making C more beautiful by not using macros with arguments Date: Sun, 31 May 2015 14:22:26 -0700 Organization: None to speak of Lines: 36 Message-ID: <876178igrx.fsf@kst-u.example.com> References: <032b4cc1-a813-4caa-a810-569e1ea3b0ab@googlegroups.com> <87h9qvkzpb.fsf@bsb.me.uk> <0f75266c-9fff-439e-98a3-4140f21e04d5@googlegroups.com> <87fv6dkd7f.fsf@bsb.me.uk> <87a8wlk5o3.fsf@bsb.me.uk> <87zj4lhxsc.fsf@bsb.me.uk> <87r3pwikdo.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="15457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/o+WlgNgzlYShtCkaJskcP" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:cvMi/3914pB7GUS6c03rNbvOrck= sha1:RQvJKxqt/ZRwDD/MyATvS2Wk3+I= Xref: csiph.com comp.lang.c:62891 Bartc writes: > On 31/05/2015 21:04, Keith Thompson wrote: [...] >> This makes it impossible to parse C without feedback from the >> symbol table. > > Yes, but not just that. It might only be possible to build the symbol > table by processing macros, typedefs and conditional code that come > before; in fact you need to implement half of a C compiler. > > Even then it can be impossible to properly parse 'f(g(h));' if 'f' for > example depends on a conditional macro which is submitted as a > compiler option, or somehow depends on the current environment. > > So for browsing C source code via automatic tools (especially in > isolation from a specific build, compiler or target), or if you want > to do a /one-off/ translation into some other form, then C can present > difficulties. > > (It doesn't make it any easier for a human reader either!) Of course C can't be reliably parsed without passing it through the preprocessor. A #include directive can apply arbitrary macro definitions, which can do extreme violence to the syntax; anything that looks like an identifier can be transformed into any arbitrary token sequence. Tools that aren't compilers can do a reasonably good job *if* the code doesn't play too many nasty tricks with the preprocessor -- and a tool can do a complete job without worrying about code generation. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"