In an assembly language we typically don’t have to worry very much about the distinction between pointers and integers. Some instructions happen to generate addresses whereas others behave arithmetically, but underneath there’s a single data type: bitvectors. At the opposite end of the PL spectrum, a high-level language won’t offer opportunities for pointer/integer confusion because the abstractions are completely firewalled off from each other. Also, of course, a high-level language may choose not to expose anything that resembles a pointer.
A pointer points to some place in memory while an integer represents a number that does not point to some place in memory.
Dr.Cyber,
IMHO GCC’s behavior is just plain buggy, it even affects linux. I’m not alone in thinking that GCC made the wrong choice here, but GCC developers are defending their position because they argue that the official C language specification doesn’t specifically define what happens when you use addresses across different structure boundaries types, so they took the liberty of redefining the “obvious” mathematical operations on pointers that we all take for granted to do something else.
While I understand that GCC is technically permitted to do anything in undefined parts of the spec, I vehemently disagree that GCC should do anything that violates the rule of least surprise. Memory management in C is already hard enough, the absolute last thing C developers need are new exceptions on how pointers work mathematically.
Edited 2018-09-25 18:59 UTC
“In an assembly language we typically don’t have to worry very much about the distinction between pointers and integers.”
That just means that in assembly you have to worry very much about the difference, confusing the two can lead to memory exceptions or worse security holes.
A high-level language offers a degree of type-safety by separating the two concepts.