post-decrement quirk?

Julie Brown julbro at auto-trol.com
Tue Jun 18 09:08:38 AEST 1991


Can anyone explain to me why the following does not work 
(at least on the Sun):

     q = q--;

'q' does not get decremented. No matter what the order of 
operations, I would expect 'q' to get decremented at some
point. It doesn't make a whole lot of sense to do this until 
you put it in a more meaningful context:


#include <stdio.h>
main()
{
   int count = 5;

   count = (count > 0) ? count-- : 0;
   printf("count %d\n", count);
}

the output from this program is :
      count 5 


pre-increment works just fine (q = --q;).

			just curious.

-- 
Julie Brown
julbro at auto-trol.COM                           Auto-trol Technology Corporation
{...}ncar!ico!auto-trol!julbro                 12500 North Washington Street
(303) 252-2856	                               Denver, CO 80241-2404



More information about the Comp.lang.c mailing list