Re: a[++j]=a[j]+a[j+1];



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 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;
This is called postfix increament which is perfectly right...

which is okk.. i think i did mistake earlier by saying
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:
That is prefix increament...
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 they
lost me somewhere 20 -21.
OK, I'll try to summerize: It has undefined behaviour, period.
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

.



Relevant Pages

  • Re: [ANNOUNCE] VICE 1.18
    ... The file src/network.c won't compile with gcc 4.0.2 under SuSE Linux 10.0. ... network.c:235: error: invalid lvalue in increment ...
    (comp.emulators.cbm)
  • Re: Versioning on Build
    ... I would love to be able to have the build number increment each time I ... compile, but I am not familiar with the correct way to do versioning in C++. ... but, while that info shows up if I look at the file properties, it still ... How can I change that version tha shows on hover? ...
    (microsoft.public.vc.mfc)
  • Re: post increment not post
    ... It's not supposed to compile. ... I intended to define class a's post operator ++ to increment ... operator int&() { ...
    (comp.lang.cpp)
  • Version info
    ... I seem to remember that there is a way to set the build number to increment ... everytime that a project is compiled. ... this information at compile time, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)