What's the difference between an integer and a pointer? (2018)
blog.regehr.org - 44 poäng - 21 kommentarer - 199557 sekunder sedan
Kommentarer (9)
- pjmlp - 5267 sekunder sedan2018, and some of the comments are already outdated, SPARK 2014 is out there with ownership model.
- glitchc - 3114 sekunder sedanI don't think GCC is doing something special, rather that -O3 might be optimizing out the subtraction. Try with -O0, I suspect you will get the same result as clang.
- bryanlarsen - 3620 sekunder sedanPointers have provenance, integers don't.
- m00dy - 1222 sekunder sedanrange of values
- stronglikedan - 3126 sekunder sedanwell, their names, for starters...
- spwa4 - 3387 sekunder sedanThere is no difference.
Yes, I'm a C programmer, how did you know?
- hn_submit - 4113 sekunder sedanContext.
- - 2295 sekunder sedan
- cowlevel - 2304 sekunder sedan> First, does this C program execute undefined behavior? It does not! Computing out-of-bounds pointers is UB but we are free to do whatever we like with integer-typed values that were derived from pointers. Second, does the C standard mandate the behavior that we saw here? It does not!
Behaviour that is not defined is undefined behaviour. Integer to pointer conversion is IDB, which is the same as UB except that a conforming compiler documents what could happen. I believe it's typically documented as unpredictable, so the same as plain UB.
Nördnytt! 🤓