Okay, so that really bothers me. I am working on an HW issue and discovered what was really strange to me. here is the function and call in question
int find_oldest_frame(int **a, int size) { int min = clock(); int **ptr; int *ptr2; int frame = 0; int i;
}
So, to make the long story short, I get a pop-up (in windows) which says that the problem was and should be closed.
When I try to replace * PTR ++; with * PTR + = 1;
The program starts. This interested me, so I used -S in gcc With the * ptr ++ version, I get this instruction:
addl $4, -20(%ebp)
with * p + = 1 I get
movl -20(%ebp), %eax movl (%eax), %eax leal 4(%eax), %edx movl -20(%ebp), %eax movl %edx, (%eax)
Which seems to me a very similar operation, therefore, assuming that I am reading it correctly,
case 1
An increment of -20 (% ebp) by 4 (assuming $ 4 means that)
case 2
we save what is in ebp for eax,
(not sure what () does), but do it again?
then grab and load the address from eax offset by 4 in edx,
now copy ebp back to eax again
now copy edx to eax,
I mean, it looks like they are doing the same thing, but for some reason * ptr ++! = * Ptr + = 1
Why? What am I missing from what I see?
EDIT: THANKS Everything now I feel special, I canโt believe that I did not realize this!