I am trying to hack the general C rules while research and try to store memory address in variable but my code failed with Segmentation fault (core dumped) when running under 64-bit system. And I know why - because of 4/8-bits (32/64-bit systems) of memory.
The question is: what primitive type (not uintptr_t) I need to satisfy both systems? long long int? My source:
int main() {
int i;
char char_array[5] = {'a', 'b', 'c', 'd', 'e'};
unsigned int hacky_nonpointer;
hacky_nonpointer = (unsigned int) char_array;
for(i=0; i < 5; i++) {
printf("[hacky_nonpointer] points to %p, which contains the char '%c'\n",
hacky_nonpointer, *((char *) hacky_nonpointer));
hacky_nonpointer = hacky_nonpointer + sizeof(char);
}
}
uintptr_t? If so, just useuint64_t– Useless Aug 21 '20 at 16:11#include <stdio.h>– user3629249 Aug 21 '20 at 20:10