[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc

Title:DECC
Notice:General DEC C discussions
Moderator:TLE::D_SMITHNTE
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2212
Total number of notes:11045

2181.0. "behavior of increment operator" by MILORD::BISHOP (The punishment that brought us peace was upon Him) Wed May 07 1997 11:53

    In the following statement, which value of tim is passed to SYS$CANTIM?
    The value before incrementing or the value after?
    
    	SYS$CANTIM (tim++, 0);
    
    Reason for asking is that DEC C T5.2-006 (as used in the build of
    OpenVMS Alpha V7.0) passes the post-increment value, but DEC C V5.2-003
    (in use for V7.1 and current Raven builds) passes the pre-increment
    value.
    
    My reading of my old C course notes is that the new behavior is
    correct, but I'd like to confirm this (i.e. was a bug fixed between
    those versions, or was it introduced then?)
    
    btw I intend to make this a moot point by changing the code to 
    
    	SYS$CANTIM (tim, 0);
    	tim++;
    
    It's safer and clearer and by the time GEM is done optimizing, the 
    code is much the same.
    
    Thanks
    
    - Richard.
T.RTitleUserPersonal
Name
DateLines
2181.1pre-increment uses ++prefix, post-increment uses postfix++XDELTA::HOFFMANSteve, OpenVMS EngineeringWed May 07 1997 12:0510
   With ++tim, the value before the increment is used, while with tim++,
   the value after the increment is used.  In either case, the value is
   incremented.

   The compiler-specific order of evaluation -- which doesn't factor in
   with this particular code fragment -- is also an important consideration.

   This appears to be a bug in T5.2-006, and your workaround should operate
   as expected on both DEC C T5.2-006, DEC C V5.2-003, and other C compilers
2181.2WIBBIN::NOYCEPulling weeds, pickin' stonesWed May 07 1997 12:217
No, Steve, you've got it backwards.

++tim increments tim, then uses the new result.

tim++ uses the old value, then increments tim.

It looks as if the "T" version is broken, but the "V" version works.
2181.3ignoranaleptic seizuresXDELTA::HOFFMANSteve, OpenVMS EngineeringWed May 07 1997 12:384
:No, Steve, you've got it backwards.

   Whoops -- brain cramp.

2181.4thanksMILORD::BISHOPThe punishment that brought us peace was upon HimWed May 07 1997 13:247
    thanks guys...what I expected (except for Steve's
    open-foot-insert-mouth routine. :-)
    
    Right now, there are some very happy devos in EDO who are no longer
    suffering from horrendous hangs in the System Code Debugger...
    
    - Richard.