Please review my pastebin. I commented exactly where it occurs, and how GDB will not access my variable.
I made a program to prove that you can store an address into an unsigned int and use it as a pointer. It works on old 32bit machine, but not on my 64 bit. I can only assume it is because of my compiler??
I made a program to prove that you can store an address into an unsigned int and use it as a pointer. It works on old 32bit machine, but not on my 64 bit. I can only assume it is because of my compiler??
Code:
//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);
}
}
Comment