Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I am trying to figure out why I get a segmentation fault at "*((char *) hacky_nonpointer)"
- //
- //This works on a 32 bit older gcc compiler on an older machine, but with gcc-4.4.3 on my
- //x64 machine, I get a segmentation fault at that point. Is it my compiler??
- //Also, GDB shoots an "Error accessing memory" when I do x/xw hacky_nonpointer. It does
- //retain it's value though.
- #include <stdio.h>
- int main() {
- int i;
- char char_array[5] = {'a', 'b', 'c', 'd', 'e'};
- int int_array[5] = {1, 2, 3, 4, 5};
- unsigned int hacky_nonpointer;
- hacky_nonpointer = (unsigned int) char_array;
- for(i=0; i < 5; i++) { // Iterate through the int array with the int_pointer.
- printf("[hacky_nonpointer] points to %p, which contains the char '%c'\n",
- hacky_nonpointer, *((char *) hacky_nonpointer));
- hacky_nonpointer = hacky_nonpointer + sizeof(char);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment