Incremented Expression passing in Turbo C
Posted: Tue Jun 29, 2004 3:58 pm
Is it a problem of Turbo C compiler ?
Consider the following code:
[c]
void main()
{
int n,d;
n=5;
printf("%d ",d = ++n + ++n);
n=5;
d = ++n + ++n;
printf("%d ", d);
}
[/c]
both printf should output same value, and it does that in vc++.
but in Turbo C first printf prints 13 and the second one 14.
I disassembled the programs in TC and found the difference, that is, for first case:
for the second case:
can anyone tell me, what is the reason ? or is it a bug of tc ?
Consider the following code:
[c]
void main()
{
int n,d;
n=5;
printf("%d ",d = ++n + ++n);
n=5;
d = ++n + ++n;
printf("%d ", d);
}
[/c]
both printf should output same value, and it does that in vc++.
but in Turbo C first printf prints 13 and the second one 14.
I disassembled the programs in TC and found the difference, that is, for first case:
Code: Select all
; n=5;
;
mov si,5
;
; d = ++n + ++n;
;
inc si
inc si
mov ax,si
add ax,si
mov di,ax
for the second case:
Code: Select all
; n = 5;
;
mov si,5
;
; printf("%d\n",d = ++n + ++n);
;
inc si
mov ax,si
inc si
mov dx,si
add ax,dx
mov di,ax
push ax
.........so on
can anyone tell me, what is the reason ? or is it a bug of tc ?