# Why a pointer is not just an integer, and GCC and Clang disagree

Original title: What's the difference between an integer and a pointer?

> Hacker News story 50587286 · language: en · submitted 2026-11-21
> Web version: https://zeli.app/story/50587286
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 103 · by [germanrabbit](<https://news.ycombinator.com/user?id=germanrabbit>) · 💬 101
[original](<https://blog.regehr.org/archives/1621>) · [HN discussion](<https://news.ycombinator.com/item?id=50587286>)

## Summary

In C, casting a pointer to an integer and back is not undefined behavior, but the standard barely says what the result means. John Regehr shows a program where GCC and Clang diverge: fabricate a pointer from an observed address difference and both update the original object, but hardcode the same offset and GCC stops believing the two pointers alias. The lesson: pointer provenance is real, and any optimizing systems language faces the same tension.

## Key quote

> It is a big mistake to try to understand pointers in a programming language as if they follow the same rules as pointer-sized integer values.

## HN discussion (101 comments)

### [quelsolaar](<https://news.ycombinator.com/item?id=50616248>)

> The argument that this is valid defined C is not entirely correct. You can not subtract one pointer form another that doesn't come from the same allocation, that is explicitly UB. But the user here subtracts one integer from the other and that is valid. However C only guarantees you can you can convert a integer to a valid pointer, if that integer has been converted from a pointer, and not been modified in any way. If the integer has been modified its implementation defined what happens. Its no longer valid standard C.
>
> C supports pointers that can have memory banks, or pointers that are consist of a hash and and an offset. Real world hardware architectures like CHERI does this and standard C supports this. In hardware like that, this would break, even if the subtraction is done on integers, and don't violate the no subtraction of pointer of different allocation rule. So no, Pointers are really not integers, even if they may look like integers on your machine.
>
> E (Member of the wg14 memory model study group.)

### [tialaramex](<https://news.ycombinator.com/item?id=50616470>)

> Quite some time after this blog was written Aria blogged about the "strict provenance experiment" for Rust, and today Aria's API (more or less) is sanctioned and Rust is defined to deliver the behaviour Aria described in the Tower of Weakenings.
>
> Here's the Rust documentation: https://doc.rust-lang.org/std/ptr/index.html#strict-provenan...
>
> So in Rust much of this is spelled out today, although of course the LLVM backend still miscompiles some programs (in Rust or indeed in C or C++) because it can be tricked into giving integers provenance even though that's clearly not what anybody wanted. Oops.
>
> However in C, which most of the examples are written in, the status is a bit less clear. Martin Uecker (who can often be found here in HN's comments) and colleagues wrote a document for ISO but that document is not (yet?) part of the ISO C standard itself. Of course in practice compilers like LLVM, GCC and MSVC need to do what the document says instead of making it up as they go, or else this matters very little.
>
> One thing which cannot be in doubt in any of these close-to-the-metal languages today, almost certainly including obscure ones you've maybe taken a shine to like Odin or Hare, is that provenance is a thing, if you're sure you don't have pointer provenance in your languages but you do have actual pointers, check with a stop watch. If your programs in that language are very slow you might be right.
>
> Because that's why this became a thing. Without provenance, pointers strangle ma […]

### [andai](<https://news.ycombinator.com/item?id=50614550>)

> Article says pointers and its are both just bitvectors, but doesn't explain what a bitvector is.
>
> It seems to be a vector of bits? Except in practice, a bitvector is just an int where you're using the binary digits to store stuff? And you gotta use these awkward bitwise operators to actually use it? (Popular in 90s video games, to save RAM!)
>
> Or was it another way of saying "ultimately it's the same pattern of ones and zeroes so you can do whatever you want with it as long as you know what you're doing" ?

### [notorandit](<https://news.ycombinator.com/item?id=50615867>)

> Assembly programmer here.
>
> Depending upon the architecture, not all values can be memory addresses (aka pointers) due to alignment constraints. Then other way around is possible as long as memory addresses have at least l the same number of bits as integers.
>
> Finally, as long as you don't dereference an integer used (casted) as a pointer, there is no difference. Like equality comparison.

### [dapperdrake](<https://news.ycombinator.com/item?id=50616675>)

> There was an old VAX or something that had a C standard library where function pointers in both C and Fortran were multiple machine words.  C was 4 words and Fortran was 6 with everything but the first two being reserved for later.  The idea was to provide additional argument and return type information in tag bits in the additional machine words.
>
> So, mathematically, pointers still are integers, because "everything" can be encoded as a natural number.  Handles like in Windows or UEFI, hardware descriptors like internal to netmap and io_uring for NIC physical memory mapped control registers, 32-bit integer page numbers within sqlite databases, or memory addresses in x86_64 registers.  Tagged numbers for counting stuff.  Just look at off_t in Linux. Or unix filesescriptor fd numbers into a tiny per-process table of each Linux process.  Some with hardware support, some without.
>
> And then stuff like ptrdiff_t in the C abstract machine.
>
> All the same idea.  And it "only works", because they are "just numbers".
>
> And then come the implementation details.

### [bryanlarsen](<https://news.ycombinator.com/item?id=50613184>)

> Pointers have provenance, integers don't.

### [kibwen](<https://news.ycombinator.com/item?id=50615578>)

> Recommended further reading in this blog series by Ralf Jung: https://www.ralfj.de/blog/2020/12/14/provenance.html

### [hn_submit](<https://news.ycombinator.com/item?id=50613050>)

> Context.

---

## Cite

- Page: https://zeli.app/story/50587286
- Date: 2026-11-21
- Source: blog.regehr.org (https://blog.regehr.org/archives/1621)
- Hacker News: https://news.ycombinator.com/item?id=50587286

## Other languages

- zh: https://zeli.app/zh/story/50587286 · markdown: https://zeli.app/zh/story/50587286.md
- ja: https://zeli.app/ja/story/50587286 · markdown: https://zeli.app/ja/story/50587286.md
- ko: https://zeli.app/ko/story/50587286 · markdown: https://zeli.app/ko/story/50587286.md
- de: https://zeli.app/de/story/50587286 · markdown: https://zeli.app/de/story/50587286.md
- es: https://zeli.app/es/story/50587286 · markdown: https://zeli.app/es/story/50587286.md
- ru: https://zeli.app/ru/story/50587286 · markdown: https://zeli.app/ru/story/50587286.md
