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 13:51:39 -0800 Organization: None to speak of Lines: 54 Message-ID: References: <87zijq5y6s.fsf@bsb.me.uk> <87lgvaiapo.fsf@gmail.com> 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="U2FsdGVkX19U6vOEAPFT+chSlupiFKRP" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2otbWHnOf6TaB6ukFWPjzhQWY7o= sha1:iP/zrVxFqMAUmdsQPAeQ/H82Wkc= Xref: csiph.com comp.lang.c:99938 Gareth Owen writes: > Keith Thompson writes: >> 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. > > The only code that I've seen that > a) doesn't (ab)use the features you mention above > b) confuses bracket matchers (emacs, specifically) > > #ifdef CAUTIOUS_DOOHICKEY_FROBNICATION > if(doohickey != NULL && FROBNICATION_DEPTH < 3) { > #else > if(doohickey != NULL) { > #endif > /// Refrobnicate the doohickey > frobnicate(doohickey); > } > > That's not a style I would use, or recommend, but I have worked on > codebases with constructs like that in it, and sometimes so many that > refactoring becomes quite an intrusive change. If I felt the need to write code like that, I'd probably put the { on its own line: #ifdef CAUTIOUS_DOOHICKEY_FROBNICATION if(doohickey != NULL && FROBNICATION_DEPTH < 3) #else if(doohickey != NULL) #endif { /// Refrobnicate the doohickey frobnicate(doohickey); } I might even consider writing something like this: if (doohickey != NULL #ifdef CAUTIOUS_DOOHICKEY_FROBNICATION && FROBNICATION_DEPTH < 3 #endif ) { /// Refrobnicate the doohickey frobnicate(doohickey); } though I'd be sympathetic to charges that it's too freaking ugly. -- 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"