This is correct, reference this in C if you don't believe me. Technically it
is because the operator is unary right associative and is 'pre' increment.
Hence, the instruction set generated is (roughly):

 

INC CNT in place ; CNT is now 4

INC CNT in place ; CNT is now 5 

LD CNT           ; 5

ADD CNT          ; Add 5

 

And the answer is 10. I presume that you can derive the sequence for your
second example from this.

 

Now contrast that with 'post' increment.

 

Jim

 

#include <stdio.h>

 

int

main(int cnt, char * argc[])

{

        int c, c1;

 

        c = 3;

        printf("Expr is %d\n, c is %d\n\n", ++c + ++c, c);

        c = 3;

        printf("Expr is %d\n, c is %d\n\n", c++ + c++, c);

}

 

 

 

From: [email protected] [mailto:[email protected]] On Behalf Of [
Xze ]
Sent: Wednesday, September 01, 2010 5:35 AM
To: [email protected]
Subject: Pre-increment

 

Hi all!

My question pertains to the way that jbase treats pre-increments

Consider the following routine:

0004     PROGRAM MY.MATH
0005
0006     CNT = 3
0007     RES = ++CNT + ++CNT
0008
0009     PRINT 'RES = ':RES
0010     RETURN
0011 END

The output result is RES = 10

if i change line 007 to RES = ++CNT + ++CNT + ++CNT,
then the output result is RES = 16

Can anybody explain this behaviour? (I expected the first case to output RES
= 9 and the second RES = 15)

My system configuration:

OS      :   AIX 5.3
jbase   : Major 5.0 , Minor 20 , Patch 0364 (Change 85159)

Regards

-- 
Please read the posting guidelines at:
http://groups.google.com/group/jBASE/web/Posting%20Guidelines
 
IMPORTANT: Type T24: at the start of the subject line for questions specific
to Globus/T24
 
To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at
http://groups.google.com/group/jBASE?hl=en

-- 
Please read the posting guidelines at: 
http://groups.google.com/group/jBASE/web/Posting%20Guidelines

IMPORTANT: Type T24: at the start of the subject line for questions specific to 
Globus/T24

To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en

Reply via email to