4 ms·
A good thought, but C’s syntax makes it a bit hairy to explicate that you’re using an integral value as a pointer: #include <stdint.h> #include <stdio.
by evincarofautumn 14y ago
A good thought, but C’s syntax makes it a bit hairy to explicate that you’re using an integral value as a pointer:
#include <stdint.h>
#include <stdio.h>
struct big_data { int i; };
void f(intptr_t p) {
printf("%d\n", ((struct big_data*)p)->i);
}
int main(int argc, char** argv) {
struct big_data data = { 42 };
intptr_t p = &data;
f(p);
return 0;
}
So there’s no real pedagogical gain. If someone understands what “a pointer is just an integer” means, then they probably understand pointers already.
- aaronblohowiak 14y agoalso, you need to be careful about your assumptions about the sizeof a pointer and the sizeof an integer.