3 ms·
It's incorrect to call a pointer an integral type. It doesn't behave like an integer (you can't add two pointers together). You can't even subtract two pointers
by shric 6y ago
It's incorrect to call a pointer an integral type. It doesn't behave like an integer (you can't add two pointers together). You can't even subtract two pointers from each other unless they point into the same array (or one element past) without causing undefined behaviour. You can't even reliably convert a pointer generally to an integer and back again unless it's a void *.
Edit: just remembered I wrote a rambling on this in 2014: https://ramblings.implicit.net/c/2014/04/21/pointers-are-not-integers.html https://ramblings.implicit.net/c/2014/04/21/pointers-are-not...
- bluetomcat 6y agoStrictly it's not an integral type as you point out, but for the purpose of introducing a beginner who might be afraid that there is "deep magic" involved, it can be a helpful comparison. Subtracting two pointers yields ptrdiff_t which is not a pointer type in itself.
- shric 6y agoPretending it's an integral type leads to all sorts of conceptual mistakes, imho. It has almost no comparable semantics to integers.