Path: utzoo!utgpu!attcan!uunet!iscuva!rickf
From: rickf@iscuva.ISCS.COM (Rick Frostad)
Newsgroups: comp.sys.atari.st
Subject: Re: Laser C bug
Message-ID: <1878@iscuva.ISCS.COM>
Date: 18 Aug 88 17:18:20 GMT
References: <365@polyof.UUCP>
Organization: ISC Systems Corporation, Spokane, WA
Lines: 84

In article <365@polyof.UUCP> jeff@polyof.UUCP (A1 jeff giordano ) writes:
>
>Actually I wouldn't call it a bug, but more a deficience in the
>grammar.  The following drove me nuts:
>
>		for(x=-1; x<=1; x++) { ... }
>I wanted to loop from -1 to 1.  However, the above is ambigous, it is an
>old style declaration.  I did not find out until I tried my prog on our
>UNIX system.  The UNIX cc gives:
>	Warning: oldstyle declaration on line xx.
>
>Laser gives no such warning and actually takes whatever the previous
>value was and drecrements it by one.  then does the loop.  not what i thought it
>would do.
>
>just thought I should let someone know.
>
>Goeffrey Giordano
>INET: jeff@polyof.poly.edu
>UUCP: ...!iguana!polyof!jeff
>
>Me?!? What do I know?  I'm just a brain dead poly student.


This illustrates both a blessing and a curse of the C language.  To most 
C compilers the following are equivalent:

		x -= 1;
		x =- 1;

Without the whitespace the compiler interpreted 'x=-1' to be the latter
rather than 'x=(-1)'.   Try using parens or whitespace.

This also demonstates one of the possible side-effects of macros.  The
following illustrates the point:

#define MINUS_ONE -1

x=MINUS_ONE;


...translated by the pre-processor to:

x=-1;

Again not what was intended.


To minimize the chance of these side-effects, always use parans for signed
numbers;  especially when defining them in macros (#defines).

#define MINUS_ONE (-1)

x=MINUS_ONE;

...translated by the pre-processor to:

x=(-1);


In either case the use of whitespace not only eliminates the problem but
also makes the code more readable...


------------------------------------------------------------------------------


          iiiiii      ssssscccccccc
         iiiiii        sscccccccccccc
        iiiiii          cccc     ccccc
       iiiiii     ss     cc      ccccc
      iiiiiis      ssccccc
     iiiiiisss       cccc
    iiiiiissssss      cc
   iiiiii     sss     cc       ccccc
  iiiiiis             ccc     ccccc
 iiiiiisss          sssccccccccccc
iiiiiissssss      sssssccccccccc


- Rick W. Frostad
- ISC Systems Corporation
- E. 22425 Appleway
- Liberty Lake, WA  99019