3 ms·
Well, like the sibling comment, I can only point to the standard. I'll give one example: the segmented memory model. In C, the difference between two pointers
by loup-vaillant 10y ago
Well, like the sibling comment, I can only point to the standard. I'll give one example: the segmented memory model. In C, the difference between two pointers is a valid operation iff they point to the same object (or one slot past it). So it works if it's the same array or malloc() block, but something as simple as
int a;
int b;
ptrdiff_t d = &b - &a;
is undefined. Modern computers, including most embedded platforms, have a flat memory model by now, and could implement the operation above without problem.
Another difference I know of is signed integer overflow. Most platforms use a 2's complement architecture, where signed overflow simply wraps around. In C, such an operation is undefined.
Yet another difference relates to pointer aliasing. On most platform, a pointer is just a pointer to a memory slot. In C, it is assumed for optimization purposes that pointers of different types cannot point to overlapping regions. This prevents practical stuff like type punning, for which you have to use unions.