Jim me eld mucker,

 

All very well and good, but ..

 

On jBASE 3.x, the answer given is 9 (and then 15 for the second test). This
is what Xze (??) was expecting and differs to what he saw on jBASE 5.x ,
answers of 10 and 16.

 

So no matter what your argument, the fact we get different answers on
different jBASE releases shows that something is wrong. As you were
responsible for the jBASE 3.x compiler and not for the jBASE 5.x compiler, I
would obviously expect the jBASE 3.x answer to be correct ;-)


You then talk about "reference this in C if you don't believe me". Now, not
as though I didn't believe you or anything, but writing a simple C program
on Suse 11.2 gives this

 

main()

{

    int cnt , res ;

    cnt = 3 ;

    res = ++cnt + ++cnt ;

    printf("cnt = %d\n",cnt);

}

 

cnt = 5

 

So that doesn't match up with either of the jBASE releases or what you had
said about C.

 

So there is obviously some behaviour that is hard to pin down with these pre
and post increments.

 

I am sure I am missing something here, and await your demolishment of this
email to prove you right again ! ;-)

 

Greg

 

From: [email protected] [mailto:[email protected]] On Behalf Of
Jim Idle
Sent: 02 September 2010 17:11
To: [email protected]
Subject: RE: Pre-increment

 

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

-- 
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