I am trying to understand the behavior of void pointers. Can someone
explain to me why I get a segfault for the following program?
#include <stdio.h>
void* plusone(void* i){
int* arg = (int*)i;
int result = (*arg + 1);
return (void*)result;
}
int main(){
void* w1 = (void*)10;
void* result = plusone(w1);
printf("%d", *(int*)result);
}
According to gdb, the cast in the first line of plusone gives the segfault.
Why??
Markus
P.S.: I compiled with gcc 3.2.2
explain to me why I get a segfault for the following program?
#include <stdio.h>
void* plusone(void* i){
int* arg = (int*)i;
int result = (*arg + 1);
return (void*)result;
}
int main(){
void* w1 = (void*)10;
void* result = plusone(w1);
printf("%d", *(int*)result);
}
According to gdb, the cast in the first line of plusone gives the segfault.
Why??
Markus
P.S.: I compiled with gcc 3.2.2
Comment