Pointer Implementation Details in C

Posted by Will Bickford on Stack Overflow See other posts from Stack Overflow or by Will Bickford
Published on 2009-08-29T21:59:10Z Indexed on 2010/03/16 17:31 UTC
Read the original article Hit count: 310

I would like to know architectures which violate the assumptions I've listed below. Also I would like to know if any of the assumptions are false for all architectures (i.e. if any of them are just completely wrong).

  1. sizeof(int *) == sizeof(char *) == sizeof(void *) == sizeof(func_ptr *)

  2. The in-memory representation of all pointers for a given architecture is the same regardless of the data type pointed to.

  3. The in-memory representation of a pointer is the same as an integer of the same bit length as the architecture.

  4. Multiplication and division of pointer data types are only forbidden by the compiler. NOTE: Yes I know this is nonsensical. What I mean is - is there hardware support to forbid this incorrect usage?

  5. All pointer values can be casted to a single integer. In other words, what architectures still make use of segments and offsets?

  6. Incrementing a pointer is equivalent to adding sizeof(the pointed data type) to the memory address stored by the pointer. If p is an int32* then p+1 is equal to the memory address 4 bytes after p.

I'm most used to pointers being used in a contiguous, virtual memory space. For that usage, I can generally get by thinking of them as addresses on a number line. See (http://stackoverflow.com/questions/1350471/pointer-comparison/1350488#1350488).

© Stack Overflow or respective owner

Related posts about pointer

Related posts about memory