Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Out of register space (ugh)" -- vi


devel / comp.lang.c / Re: How to disambiguate macro?

SubjectAuthor
* How to disambiguate macro?John Forkosh
+* Re: How to disambiguate macro?Ben Bacarisse
|`* Re: How to disambiguate macro?John Forkosh
| `* Re: How to disambiguate macro?Ben Bacarisse
|  `* Re: How to disambiguate macro?John Forkosh
|   +- Re: How to disambiguate macro?Andrey Tarasevich
|   +* Re: How to disambiguate macro?Keith Thompson
|   |`* Re: How to disambiguate macro?John Forkosh
|   | +- Re: How to disambiguate macro?Keith Thompson
|   | `- Re: How to disambiguate macro?James Kuyper
|   +* Re: How to disambiguate macro?James Kuyper
|   |`* Re: How to disambiguate macro?John Forkosh
|   | +- Re: How to disambiguate macro?Bart
|   | +- Re: How to disambiguate macro?David Brown
|   | +* Re: How to disambiguate macro?Ben Bacarisse
|   | |+* Re: How to disambiguate macro?Ben Bacarisse
|   | ||`* Re: How to disambiguate macro?Bart
|   | || +- Re: How to disambiguate macro?David Brown
|   | || `* Re: How to disambiguate macro?Ben Bacarisse
|   | ||  `* Re: How to disambiguate macro?Bart
|   | ||   +* Re: How to disambiguate macro?David Brown
|   | ||   |+* Re: How to disambiguate macro?Manfred
|   | ||   ||`- Re: How to disambiguate macro?David Brown
|   | ||   |`* Re: How to disambiguate macro?Bart
|   | ||   | `* Re: How to disambiguate macro?David Brown
|   | ||   |  +- Re: How to disambiguate macro?Bart
|   | ||   |  `* Re: How to disambiguate macro?antispam
|   | ||   |   `- Re: How to disambiguate macro?David Brown
|   | ||   `- Re: How to disambiguate macro?Ben Bacarisse
|   | |`* Re: How to disambiguate macro?Manfred
|   | | `- Re: How to disambiguate macro?Scott Lurndal
|   | +- Re: How to disambiguate macro?Andrey Tarasevich
|   | `* Re: How to disambiguate macro?James Kuyper
|   |  +- Re: How to disambiguate macro?Stefan Ram
|   |  +* Re: How to disambiguate macro?Keith Thompson
|   |  |`* Re: How to disambiguate macro?John Forkosh
|   |  | `- Re: How to disambiguate macro?James Kuyper
|   |  +* Re: How to disambiguate macro?John Forkosh
|   |  |+- Re: How to disambiguate macro?Scott Lurndal
|   |  |`- Re: How to disambiguate macro?Ben Bacarisse
|   |  `* OT: possessive adjectives (Was: How to disambiguate macro?)Manfred
|   |   `- Re: OT: possessive adjectivesTim Rentsch
|   `- Re: How to disambiguate macro?Tim Rentsch
+* Re: How to disambiguate macro?David Brown
|`* Re: How to disambiguate macro?John Forkosh
| +* Re: How to disambiguate macro?Bart
| |`- Re: How to disambiguate macro?David Brown
| +- Re: How to disambiguate macro?David Brown
| +- Re: How to disambiguate macro?David Brown
| `- Re: How to disambiguate macro?Tim Rentsch
+- Re: How to disambiguate macro?John Forkosh
`- Re: How to disambiguate macro?Andrey Tarasevich

Pages:123
Re: How to disambiguate macro?

<861r6vyc99.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17958&group=comp.lang.c#17958

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to disambiguate macro?
Date: Sat, 14 Aug 2021 13:58:26 -0700
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <861r6vyc99.fsf@linuxsc.com>
References: <sd6b8j$498$1@reader1.panix.com> <878s21gney.fsf@bsb.me.uk> <sd6h5j$hng$2@reader1.panix.com> <87fsw9m4qd.fsf@bsb.me.uk> <sd7ud2$hkh$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="e69182db6e8a2e097c43a26c68c35bd4";
logging-data="7567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19icsKenfvTyyM+HTYFqo+rTgK9IIgMQGU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:0uFXOKYEgfGVIGuGNF8zehPZgpE=
sha1:ITDsBJ4tvh8yjiIooS6sqpenUc8=
 by: Tim Rentsch - Sat, 14 Aug 2021 20:58 UTC

John Forkosh <forkosh@panix.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>
>> John Forkosh <forkosh@panix.com> writes:
>>
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>>>
>>>> John Forkosh <forkosh@panix.com> writes:
>>>>
>>>>> Consider a macro of the form
>>>>> /* --- set north=parent,south=child,east=next,
>>>>> west=previous link of node --- */
>>>>> #define setlink(ptr,nsew,link) if ( checknode(ptr) ) \
>>>>> ((node *)(ptr))->nsew = (node *)(link)
>>>>> Not important exactly what it does, just the if(xxx)yyy
>>>>> construction.
>>>>>
>>>>> Now, suppose I want to use it like
>>>>> if ( xxx ) setlink(a,b,c); else yyy;
>>>>> Then the compiler warns that the binding of that else yyy; is
>>>>> ambiguous.
>>>>>
>>>>> I clearly mean
>>>>> if ( xxx ) {setlink(a,b,c);} else yyy;
>>>>> but it's cumbersome and inelegant to write it that way again and again.
>>>>>
>>>>> Likewise, if I try to define the macro with the {}'s (and the
>>>>> trailing ;)
>>>>> #define setlink(ptr,nsew,link) { if ( checknode(ptr) ) \
>>>>> ((node *)(ptr))->nsew = (node *)(link); }
>>>>> Then writing setlink(a,b,c); in the code has that extraneous ;
>>>>> which can then again cause the same kind of confusion. But
>>>>> omitting the ; just looks wrong and ugly.
>>>>>
>>>>> So what's a way to define the macro that simultaneously removes
>>>>> any potential semantic confusion without introducing the
>>>>> necessity of any unpretty syntax?
>>>>
>>>> There is a conventional idiom for this:
>>>>
>>>> #define setlink(ptr,nsew,link) \
>>>> do { \
>>>> if ( checknode(ptr) ) \
>>>> ((node *)(ptr))->nsew = (node *)(link); \
>>>> } while (0)
>>>>
>>>> (The {}s are optional in this case.)
>>>
>>> Thanks. Okay, I'll try adopting that conventional style.
>>> Looks a bit elaborate to me, but if that's the convention
>>> then I guess I can get comfortable with it.
>>
>> Most C programmers won't bat an eyelid at it, but I agree it's
>> clumsy.
>>
>> When the contingent action is actually just an expression, you can
>> avoid the if (...) altogether like this:
>>
>> #define setlink(ptr,nsew,link) \
>> ( checknode(ptr) && (((node *)(ptr))->nsew = (node *)(link)) )
>>
>> so that there are no 'else' issues at all.
>
> Thanks, again, for the alternative solution. I actually like it a
> little better since it avoids the klutzy do-while construction that
> has no useful purpose and might only confuse the casual reader,
> i.e., "What the heck is he doing that for?" But then again, I never
> much liked relying that (a&&b) always evaluates a first, immediately
> becoming 0 without evaluating b at all if a is itself 0. You never
> know exactly what the next C standard might mess around with.
> But your suggestion itself suggested the more explicit version
> #define setlink(ptr,nsew,link) \
> ( checknode(ptr)? (((node *)(ptr))->nsew = (node *)(link)) : 0 )
> which I think accomplishes the same thing with explicitly visible
> logic.

In cases like this one I usually find an expressional form works
better than a statement form, and ?: better than && (unless of
course the second part of the && is also a predicate and the
overall value is important, in which case it can depend on the
subexpressions involved).

Re: How to disambiguate macro?

<86wnonw7sz.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17959&group=comp.lang.c#17959

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news2.arglkargh.de!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to disambiguate macro?
Date: Sat, 14 Aug 2021 23:17:32 -0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <86wnonw7sz.fsf@linuxsc.com>
References: <sd6b8j$498$1@reader1.panix.com> <sd6gqq$sjl$1@dont-email.me> <sd6igi$jos$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="4dd8ce6a7e240a14eec73d2f816adcd2";
logging-data="30568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dg7MzTXQK9ewvEKBgZ2HzkPNPPJkRYf8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:bSorVGIJiyn3hzfBc39LbU2XFBs=
sha1:5bXFZLogj6Sq/Bc9u/2Lt+oIGfU=
 by: Tim Rentsch - Sun, 15 Aug 2021 06:17 UTC

John Forkosh <forkosh@panix.com> writes:

> David Brown <david.brown@hesbynett.no> wrote:

[...]

>> And I recommend you get in the habit of writing :
>> if (xxx) {
>> setlink(a, b, c);
>> } else {
>> yyy;
>> }
>> People vary in their opinions and styles, of course, ...
>
> Yuk! My, but that's ugly. :) For just one statement in the
> if-clause and/or else-clause, I typically wouldn't use {}'s at
> all. And for just a few statements, I typically write it like
> if (xxx) {
> setlink(a, b, c);
> getlink(d, e, f); }
> else {
> yyy;
> zzz; }

Despite your visceral reaction, the layout you suggest here is
objectively inferior along at least one important axis. Studies
of various rules for bracketing layout have found that lining up
closing brackets (which are braces in this case) with the start
of their corresponding opening lines (ie, like the quoted example
recommendation) gives the lowest error rates of all the layout
styles looked at (including the "lisp style" layout you suggest).
The layout you prefer has higher error rates than the "ugly"
layout you dislike. I think any developer who is serious about
writing good code would want to follow a layout style that has
lower error rates, whatever their personal reactions might be.

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor