home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: techfak.uni-bielefeld.de!isthesin
- From: isthesin@techfak.uni-bielefeld.de (Stephan Thesing)
- Subject: Re: Is this a SAS/C bug or have I coded it wrong?
- Message-ID: <DKns5B.449@hermes.hrz.uni-bielefeld.de>
- Sender: isthesin@TechFak.Uni-Bielefeld.DE (Stephan Thesing)
- Date: Thu, 4 Jan 1996 13:29:35 GMT
- References: <4cfrc5$gsc@misery.millcomm.com>
- Nntp-Posting-Host: moos.techfak.uni-bielefeld.de
- Organization: Universitaet Bielefeld, Technische Fakultaet.
- X-Newsreader: xrn 8.01
-
- In article <4cfrc5$gsc@misery.millcomm.com>, llucius@millcomm.com (Yambo) writes:
- |> Is this a SAS/C bug or am I getting more blind???
- |>
- |> =========================================================================
- |> The following code:
- |> =========================================================================
- |>
- |> tmpbuf[10];
- |>
- |> int
- |> test( void )
- |> {
- |>
- |> if ( tmpbuf[0] & 0x1f == 1 )
- |> return 1;
- |>
- |> return 0;
- |> }
- |>
-
- No this is not a bug and yes, I am afraid you are getting more blind ;-)
-
- The problem lies in the expression 'tmpbuf[0] & 0x1f == 1' which is
- equivalent to (according to the precedence rules of C):
- 'tmpbuf[0] & (0x1f == 1)' instead of (the intended)
- '(tmpbuf[0] & 0x1f) ==1'
- Since 0x1f!=1, the compiler can optimise this to 'tmpbuf[0] & 0', which is
- always 0 and since tmpbuf[0] contains no side-effects, this is
- optimised to 0.
-
- In fact, one may argue that the precedence rules of C are somewhat broken,
- so my personal advice is:
- PUT BRACKETS AROUND EVERYTHING, except that one can expect that
- addittion and multiplication have the usual precedences (and subtraction, division
- too :-)
-
- Bye....
- Stephan
-
-
-
- |> =========================================================================
- |> Produces:
- |> =========================================================================
- |> SECTION text,CODE
- |> __code:
- |> test:
- |> ___test__1:
- |> MOVEQ.L #$0,D0 ;7000
- |> ___test__2:
- |> RTS ;4e75
- |> __const:
- |> __strings:
- |> XDEF test
- |>
- |> SECTION __MERGED,BSS
- |> __MERGEDBSS
- |> tmpbuf:
- |> DS.B 40
- |> XDEF tmpbuf
- |> END
- |> =========================================================================
- |> Is this right? Where'd the "IF" go? Do I have it coded wrong?
- |>
- |> TIA
- |>
- |> --
- |> __ Y_ a_ m_ b_ o_ | The leanest, meanest, fightinest sweet tater on Earth!
- |> oo o oo o o |
- |> o o o | llucius@millcomm.com
- |> o oo o o |
- |> -- -- -- -- -- -- | http://www.millcomm.com/~llucius/index.html (coming soon)
- |>
-
- --
- ===============================================
- = Stephan Thesing =
- = AG Praktische Informatik =
- = Technische Fakult"at =
- = Universit"at Bielefeld =
- ===============================================
-