4 ms·
Apparently it's new to some people that C is a statically-typed, weakly-typed language.
by devishard 10y ago
Apparently it's new to some people that C is a statically-typed, weakly-typed language.
- castratikron 10y agoIf 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.