:: Re: [DNG] Icerbergs aren't small ju…
Kezdőlap
Delete this message
Reply to this message
Szerző: Hendrik Boom
Dátum:  
Címzett: dng
Tárgy: Re: [DNG] Icerbergs aren't small just because they're mostly underwater
On Mon, Jan 25, 2016 at 01:47:46PM +0100, Didier Kryn wrote:
> Le 25/01/2016 13:23, Rainer Weikusat a écrit :
> >     while (*r) if (*r++ == '/') n = r;

>
>     Does it mean

>
>     while (*r)
>       {
>         if (*r == '/')
>     {
>            n = r;
>            r++;
>         }
>       }

>
> or
>
>     while (*r)
>       {
>         if (*r == '/')
>     {
>            r++;
>            n = r;
>         }
>       }


Neither. The incrementation in the original is not condiitional on
the rquality test. Which means that in the original, n gets assigned
the address of the character *after* the last '/' found.

In the other versions you get an infinite loop as soon as you
encounter a character that isn't '/'.

-- hendrik

>
>
>     I think the second answer is the good one. It is more readable
> and less error-prone than your example and the compiler will produce
> exactly the same instructions. You don't need to do the work of the
> compiler; it does it better. Better concentrate on writing programs
> easier to read and less error-prone. These pre-increment and
> post-increment instructions should be deprecated - I already
> advocated that on this list, although it is not the place :-)

>
>     The reason why seasonned programmers prefer the kind of
> expression you wrote, with post-increment, is a perfect example of a
> style dictated by pure aesthetics. This an error I used to make when
> I was younger, but, with age and learning, I have found true reasons
> to do otherwise.

>
>     Didier

>
>     Didier

>
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng