[sane-devel] C undefined operations in sane-backends-1.0.7-b

Joachim Backes Joachim Backes <backes@rhrk.uni-kl.de>
Thu, 24 Jan 2002 08:49:56 +0100 (CET)


Hi, guys,

i do no understand this discussion about the code fragment

        bit = ++bit % 8;

1. Since 20 years, C is my favorite programming language
2. Since some years, I give classes in C
3. The code line "bit = ++bit % 8", is fully correct.
   Reason:
      a) ++ has higher priority than %
      b) What happens: i) bit will be incremented
                       ii) the modulo 8 operation is done
                       iii) the result will be stored in bit
4. Meaning of "bit = ++bit"??? The same does "++bit"
5. None of my C compilers (gcc or IRIX c compiler) report
   any warning.

6. RESULT: The code "bit = ++bit % 8" is OK!
7. The compiler which produces the warning is buggy!

Regards

Joachim Backes

--

Joachim Backes <backes@rhrk.uni-kl.de>       | Univ. of Kaiserslautern
Computer Center, High Performance Computing  | Phone: +49-631-205-2438 
D-67653 Kaiserslautern, PO Box 3049, Germany | Fax:   +49-631-205-3056 
---------------------------------------------+------------------------
WWW: http://hlrwm.rhrk.uni-kl.de/home/staff/backes.html  

        
On 24-Jan-2002 Karsten Festag wrote: 
>  Hi,
>  
>  I'll split
>   bit = ++bit % 8;
>  in the two lines
>   bit = ++bit;
>   bit %= 8;
>  
>  in microtek2.c
>  
>  Henning, could you do this for me in CVS?
>  
>  Thanks
>  
>  Karsten
>  
>  Tim Waugh schrieb:
> > On Wed, Jan 23, 2002 at 09:43:35PM +0100, Henning 
> > Meier-Geinitz wrote: 
> > 
> > > This is with gcc-3.x? I don't get them with gcc 2.95.4.
> > 
> > Yes.
> > 
> > > > They
> > > > are for things like:
> > > > 
> > > >         bit = ++bit % 8;
> > > > 
> > > > which are indeed undefined.
> > > 
> > > Because it's not clear if bit should be incremented and 
> > then the right 
> > > side assigned to it or vice versa? Or what's the excat 
> > problem? 
> > 
> > Yes, that's right.  There is only one sequence point in 
> > 'bit = ++bit % 
> > 8;', at the end, and so the operations can happen in any 
> > order.  There 
> > are two assignments to 'bit': the '=' operation and the 
> > '++' 
> > operation.
> > 
> > Tim.
> > */
> > 
> >
>  _______________________________________________
>  Sane-devel mailing list
>  Sane-devel@www.mostang.com
>  http://www.mostang.com/mailman/listinfo/sane-devel