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

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

Hi,

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.

It’s defined by the C specification. Left hand side expression
of logical operator must be evaluated before right hand side.

Anyway there are other places in the Windows code which rely heaviest
on internal MSVC stuff. This is an unecessary complicated and fragile
design

Agree.

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.

I supect ruby-core.

···

At Fri, 11 Oct 2002 02:15:25 +0900, Friedrich Dominicus wrote:


Nobu Nakada

“Peter Schueller” peter.schueller@solution-x.com writes:

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
Ah yes I see.

One should check before posting and not just rely on one’s memory…

Anyway the other points still stand as I wrote.

  • reliance on compiler internals
  • another things which I still find not good are the comparisons of
    signed and unsigned and handling unsigned integer as if they were
    signed.

Why is that?

Regards
Friedrich