I just tested these codes on my (typical) box, the first one is really a stupid head:
kill(){kill();}
main(){kill();}
It gives me immediate segfault. The second code using value call as I want see some numbers:
#include <stdio.h>
kill(){
unsigned long int duh;
printf("%d",duh); duh++;
kill (duh);
}
main(){
kill();
}
It gives me segfault after 7.7 secs (minus delay of my reflex). The last part of output is:
...-1207865356-1207865356-1207865356-1207865356-1207865356-1207865356-120786Segmentation fault
I just don't know how it generates the same number on and on. Anyone'd like to explain?
The another one using pointer call:
#include <stdio.h>
kill(long int *victim){
printf("%d",*victim);
*victim ++;
kill (&victim);
}
main(){
long int number=0;
kill(&number);
}
This one is about 11.3 secs and show this at my shell:
...-1207865356-1207865356-1207865356-1207865356-1207865356-1207865356-120786Segmentation fault
It just shows me the same kind of number I don't know what it is really, though it's different now.
To me, it just prove pointer call is better than value call about memory management :D
0 rants:
Post a Comment