Re: a[++j]=a[j]+a[j+1];
- From: "Abdo Haji-Ali" <ahali@xxxxxxxxxxxx>
- Date: 12 Apr 2006 05:37:16 -0700
7:This is called postfix increament which is perfectly right...
8: int k = 0;
00401028 mov dword ptr [ebp-4],0
9:
10: k = k++;
0040102F mov eax,dword ptr [ebp-4] ; k is loaded
00401032 mov dword ptr [ebp-4],eax ; k is stored so that k =
k
00401035 mov ecx,dword ptr [ebp-4] ; k is loaded
00401038 add ecx,1 ; k is incremented
by 1
0040103B mov dword ptr [ebp-4],ecx ; incremented k is stored.
11:
12: printf("\n %d", k);
0040103E mov edx,dword ptr [ebp-4]
00401041 push edx
00401042 push offset string "\n %d" (0042001c)
00401047 call printf (004010b0)
0040104C add esp,8
Yes, its a kind of vague that assignment is happening before increment.
so its
k = k;
k = k + 1;
which is okk.. i think i did mistake earlier by sayingThat is prefix increament...
k = k+ 1;
k = k;
since k++; means first assigment then increment.
u can see this code now...
00401026 rep stos dword ptr [edi]
7:
8: int k = 0;
00401028 mov dword ptr [ebp-4],0
9:
10: k = ++k;
0040102F mov eax,dword ptr [ebp-4] ; k is loaded
00401032 add eax,1 ; k is incremented
00401035 mov dword ptr [ebp-4],eax ; k is stored
00401038 mov ecx,dword ptr [ebp-4] ; k is loaded
0040103B mov dword ptr [ebp-4],ecx ; k is stored
11:
This code has nothing to do with the OP code, and it's perfectly right,
google for postfix and prefix increament in C...
I'm really too lazy to go thro the whole 37 comments. I tried but theyOK, I'll try to summerize: It has undefined behaviour, period.
lost me somewhere 20 -21.
While you can compile the OP code with any C compiler and get some
results to argue with, this can't be confirmed on all compilers, or
worse in all cases.
Abdo Haji-Ali
Programmer
In|Framez
.
- Follow-Ups:
- Re: a[++j]=a[j]+a[j+1];
- From: Abdo Haji-Ali
- Re: a[++j]=a[j]+a[j+1];
- From: Naresh
- Re: a[++j]=a[j]+a[j+1];
- References:
- a[++j]=a[j]+a[j+1];
- From: RSoIsCaIrLiIoA
- Re: a[++j]=a[j]+a[j+1];
- From: Abdo Haji-Ali
- Re: a[++j]=a[j]+a[j+1];
- From: Keith Thompson
- Re: a[++j]=a[j]+a[j+1];
- From: chjiangwh
- Re: a[++j]=a[j]+a[j+1];
- From: Keith Thompson
- Re: a[++j]=a[j]+a[j+1];
- From: Naresh
- Re: a[++j]=a[j]+a[j+1];
- From: Abdo Haji-Ali
- Re: a[++j]=a[j]+a[j+1];
- From: Naresh
- a[++j]=a[j]+a[j+1];
- Prev by Date: Re: sorting (was Re: VERY URGENT C PROGRAM)
- Next by Date: Re: loop question
- Previous by thread: Re: a[++j]=a[j]+a[j+1];
- Next by thread: Re: a[++j]=a[j]+a[j+1];
- Index(es):
Relevant Pages
|