Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: gcc needs a curly bracket matching/counting function Date: Tue, 20 Dec 2016 12:16:38 -0800 Organization: None to speak of Lines: 39 Message-ID: References: <87zijq5y6s.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="b8044c752840ceb89291b47395d36dfc"; logging-data="5456"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9ZlU+FSSJn5BbNspc6WvA" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:GxJUhDM3ChCcuXeXbuIU69EwmP8= sha1:17rQ0KmKvwBXGoPZHB9y/CS6J5E= Xref: csiph.com comp.lang.c:99933 BartC writes: > On 20/12/2016 18:52, DFS wrote: >> On 12/20/2016 12:04 PM, Ben Bacarisse wrote: >>> #define OPEN { >>> >>> int main(void) OPEN } >>> >>> >> >> This one's easy: delete or ignore the #define line and replace ' OPEN ' >> with an opening curly bracket every time it's found. When I say delete >> I don't mean alter the source of course. > > It's a bit harder than that. OPEN could result from expanding another macro. > > Or there could be 100 macros all defined as {, or that include { in > their definition. > > You also now have to scan and look up all identifiers, as well as having > to actually deal with #define and #undef. > > But OPEN could also be defined inside an #include file. Or is part of a > conditional block so that it might be defined as { or } or anything else > according to some compiler option. > > So you can't deal with it 100% without implementing a full > pre-processor, and even that might depend on how a compiler is invoked. Yes, but dealing with it 99% is probably good enough. If the code doesn't use macros, digraphs, or trigraphs to hide braces, existing tools can be used to find any missing braces. If it does, I probably don't care about fixing it. -- 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"