Yeah, but that doesn't help the person reading the code. Type annotations are more for the human than the computer.
Pointers must be special. (they're not).
Pointer arithmetic takes into account structure size. ints do not. The following are not identical:
/* this works */
int array[10];
int* pointer = array;
int secondElement = *(pointer + 1);
/* this will likely crash */
int array[10];
int pointer = (int)array;
int secondElement = *(int*)(pointer + 1);
In the old days, a number of architectures actually had pointers that were a different size than ints; in fact, I think that on a modern IA32 architecture in segmented mode a far pointer is actually 48 bits. There also have been architectures where, say, int * and char * were different sizes (whether C ever ran on such computers is a different story, but when C was first developed its features and syntax were motivated by the experience of the programmers who worked on it, and they had overwhelmingly come from the punchcard/microcomputer world.)
View all comments
Show parent comment
0
u/[deleted] Jul 23 '08
Yes, but you can store addresses in integers, so why use pointers? Pointers must be special. (they're not).