January 09, 2004
C wrote:
> Hmm, when I compile this
> 
> import std.c.stdio;
> 
> void main () {
> 
>  if ( 0 <> 1 ) puts("true");
> 
> }
> 
> it fails with :
> 
> Assertion failure: '0' on line 487 in file 'constfold.c'
> 
> abnormal program termination
> 
> however != works fine.
> 
> ?
> 
> C

Now there's something people coming from BASIC will run into.

The D expression 'x <> y', when applied to integers, is equivalent to
'x == y'! (the exact opposite of what they think it means)

 -- andy
January 09, 2004
Andy Friesen wrote:
> Now there's something people coming from BASIC will run into.
> 
> The D expression 'x <> y', when applied to integers, is equivalent to
> 'x == y'! (the exact opposite of what they think it means)
> 
>  -- andy

errrr wait.  No, I'm having a Monday. (on Friday!)

 -- andy
January 09, 2004
Hmm.  It seems "<>" is not supported in case of comparison of integers.
So, the integers may be implicitly casted to floating points and compared,
and it actually works when one or both operands are variables.
However, it causes the error when both operands are integer literals.

/* in "Expression *CmpExp::constFold()" in "constfold.c" */
480:    switch (op)
481:    {
482:        case TOKlt:     n = n1 <  n2;   break;
483:        case TOKle:     n = n1 <= n2;   break;
484:        case TOKgt:     n = n1 >  n2;   break;
485:        case TOKge:     n = n1 >= n2;   break;
486:        default:
487:            assert(0);  /* <- Here! */
488:    }

I guess that this function analyses a relational expression of two integer
literals.
But, it doesn't take into account "<>", "<>=", etc.



"C" <dont@respond.com> wrote in message news:btmpmj$171k$1@digitaldaemon.com...
> Hmm, when I compile this
>
> import std.c.stdio;
>
> void main () {
>
>  if ( 0 <> 1 ) puts("true");
>
> }
>
> it fails with :
>
> Assertion failure: '0' on line 487 in file 'constfold.c'
>
> abnormal program termination
>
> however != works fine.
>
> ?
>
> C
>
> "Robert" <no@spam.ne.jp> wrote in message news:btlsfh$2roq$1@digitaldaemon.com...
> > "<>" is a valid D operator,
> > equivalent to "!=" unless one or both of operands is a NaN.
> >
> > "C" <dont@respond.com> wrote in message news:btlb1d$1vtl$1@digitaldaemon.com...
> > > if(cast(int) guess <> answer)
> > >
> > > ?
> > >
> > > is it vb uses that as a != operator ?
> > >
> > > C
> > >
> > > "J C Calvarese" <jcc7@cox.net> wrote in message news:btl20o$1id1$1@digitaldaemon.com...
> > > > Örk wrote:
> > > > > How to use scanf in D ?
> > > > > Or how to read integer and strings like in C with scanf ?
> > > > > Örk
> > > >
> > > > Here's some webpages that might be helpful: http://www.digitalmars.com/rtl/stdio.html#fscanf http://www.cplusplus.com/ref/cstdio/scanf.html
> > > >
> > > >
> > > > Here's an example in D:
> > > >
> > > > import std.c.stdio;
> > > >
> > > > int main()
> > > > {
> > > > const int answer = 10;
> > > > float guess;
> > > > int i;
> > > > char[80] name;
> > > >
> > > >
> > > > printf("Yo! What's your name? ");
> > > > scanf("%s", &name);
> > > >
> > > > printf("Pick a whole number: ");
> > > > scanf("%d", &i);
> > > > printf("You picked %d as a whole number.\n\n", i);
> > > >
> > > > printf("Guess a number: ");
> > > > scanf("%f", &guess);
> > > >
> > > > printf("\nHey, %.*s, ", name);
> > > >
> > > > if(cast(int) guess <> answer)
> > > >
> > > > if(answer == guess)
> > > > printf("answer = %f.", guess);
> > > > else if(answer > guess)
> > > > printf("answer > guess.");
> > > > else if(answer < guess)
> > > > {
> > > > printf("answer < guess.");
> > > > }
> > > > else
> > > > printf("Dude, that wasn't a number.");
> > > > printf("\n");
> > > >
> > > > return 0;
> > > > }
> > > >
> > > >
> > > >
> > > > --
> > > > Justin
> > > > http://jcc_7.tripod.com/d/
> > >
> > >
> >
>
>

1 2
Next ›   Last »