[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small problem in a if condition

From: John W. Eaton
Subject: Re: Small problem in a if condition
Date: Mon, 2 Feb 2004 09:48:31 -0600

On  2-Feb-2004, Pol <address@hidden> wrote:

| On Sun, 1 Feb 2004 11:12:27 -0600
| "John W. Eaton" <address@hidden> wrote:
| > What version of Octave are you using?  I think the == operator should
| > work for character strings with either 2.0.17 or 2.1.50.
| [~]$ octave --version
| GNU Octave, version 2.1.50 (i686-pc-linux-gnu).

OK, I see now that the problem in your function was that you were
doing something like this:

  x = 1;

  if (x == "?")

This doesn't work in 2.1.50, but does in the current sources (and
probably 2.1.53, though I haven't checked).

So the current behavior is that for a mixed-type comparison like
this, the test will return true if the ASCII value of the character is
equal to the integer.  So in the above, if X is 63, then the body of
the IF block will be executed.  I guess we are getting closer to
bug-for-bug compatibility.  Is this really what people want?

I suspect that this behavior leads to subtle bugs as many people
will think that what the == operator is doing is the equivalent of

  isstr (x) && x == "?"         ## this is what strcmp does

instead of

  x == toascii ("?")

Just out of curiosity, how did you expect the == tests in your code to


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]