of course the first code will work
because ny-- is a post-decrement (so it would not matter anyway)
and because the && operator is 'shortcut-evaluated' and that means
that the first operand MUST be evaluated before the second
(if the first evaluates to 0, the second will not even be evaluated)

also, your re-written piece of code will exit with ny 1 higher than matz's
code

peter

----- Original Message -----
From: "Friedrich Dominicus" <frido / q-software-solutions.com>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Thursday, October 10, 2002 7:15 PM
Subject: a strange construct (which lead to unspecified behavior AFAIK)


> Am not sure if this is the right place to post it or better contact
> Matz directly but I do think there are some very dubious constructs in
> the sources:
> example:
> bignums.c
> function bigdevrem around line 1225
> while (ny-- && !zds[ny])
> ;
>
> This is even a bit reformatted for better readability the ; is placed
> exactly behind the closing brace (which is really not a good idea)
>
> I do think one can not expect it to work how it's intented. It's not
> guaranteed that ny-- is evaluated before it is accessed in zds.
>
>
> I re-wrote it this way:
> while (ny && !zds[ny-1])
> --ny;
>
> Which is defined, and much more readable IMO.
>
> Anyway there are other places in the Windows code which rely heaviest
> on internal MSVC stuff. This is an unecessary complicated and fragile
> design
>
>
> I don't know if this is the right place to discuss that, if you do
> think there is a better place, please let me know.
>
> Regards
> Friedrich
>
>
>