home *** CD-ROM | disk | FTP | other *** search
- Path: strauss.udel.edu!not-for-mail
- From: jcorig@strauss.udel.edu (John Pat Corigliano)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Is this a SAS/C bug or have I coded it wrong?
- Date: 7 Jan 1996 01:07:05 -0500
- Organization: University of Delaware
- Message-ID: <4cnnu9$eua@strauss.udel.edu>
- References: <4cfrc5$gsc@misery.millcomm.com> <4cm9kc$kf7@news.isc.rit.edu>
- NNTP-Posting-Host: strauss.udel.edu
-
- In article <4cm9kc$kf7@news.isc.rit.edu>, <mjp3783@alpha.isc.rit.edu> wrote:
- >In article <4cfrc5$gsc@misery.millcomm.com>, llucius@millcomm.com (Yambo) writes:
- >> test( void )
- >> {
- >>
- >> if ( tmpbuf[0] & 0x1f == 1 )
- >> return 1;
- >>
- >> return 0;
- >> }
- >
- >No, this is not a bug, this is optimization. If I type:
- >if (1==2) a(); else b();
- >
- >isn't that, really, the same as
- >b();
- >???
-
- Well, you could at least tell him why ;) It is a precedence problem.
- The == operator has a higher precedence than the & operator, so the
- code really is this:
-
- if (tmpbuf[0] & (0x1f == 1))
-
- Since 0x1f != 1, this conditional is always equal to 0 (FALSE). Therefore,
- SAS sees the code as:
-
- if (tmpbuf[0] & 0)
-
- Since any number AND 0 will be 0, the statement really is:
-
- if (0) return 1;
- else return 0;
-
- And this is why the asm code sets D0 to 0 and returns.
- --
- John Corigliano jcorig@strauss.udel.edu
- Computer and Information Science University of Delaware
- --
- "Never drive a car when your dead." - Tom Waits
-