2 ms·
If you're talking about the cast from an int literal to a char pointer, that's not what's happening. That's common C shorthand for incrementing a pointer to poi
by castratikron 10y ago
If you're talking about the cast from an int literal to a char pointer, that's not what's happening. That's common C shorthand for incrementing a pointer to point to the next element.
For example, the char pointer increment compiles to:
4004fb: 48 83 c0 01 add $0x1,%rax
While an int pointer increment compiles to:
40050c: 48 83 c0 04 add $0x4,%rax
Because on my particular platform, an int is 4 bytes and a char is 1 byte and the memory is byte addressable.
- devishard 10y agoI'm aware of what's happening. It's definitely a norm in C and it produces desirable results in many cases (I've written similar structures myself many times). All I'm saying is that from a type perspective it's a bizarre choice to allow that.