4 ms·
Few of the top of my head: 1. Performance reasons. For example: zero copy data structures, mutable data structures, controlling data locality. 2. Direct memor
by csmithuk 13y ago
Few of the top of my head:
1. Performance reasons. For example: zero copy data structures, mutable data structures, controlling data locality.
2. Direct memory mapped hardware access. For example: device drivers, kernel, embedded systems, microcontrollers.
3. Bitwise and machine specific conversions. For example: endianess conversions.
4. Structure type coercion. For example: object systems, tagged data structures etc.
- pjmlp 13y agoAll of those examples are possible in safe systems programming languages like Modula-2 and Ada, with the difference that only the tiny spot where it matters is marked explicitly unsafe. Whereas in C there is no way to distinguish between unsafe and safe code.
- numeromancer 13y ago2. Direct memory mapped hardware access. For example: device drivers, kernel, embedded systems, microcontrollers. Of course doing this usually means your code isn't portable, sometimes not even to other versions of the same compiler. I often wish C had a defined order for bitfields, for example. One of the things I do to help debug & test embedded code is to factor out code which isn't dependent on the hardware platform (eg communication protocols) into a library, and compile it for, and write test programs to test them on, the host. So even embedded code is often best written to be as portable as possible.
- fanf2 13y agoIf you are doing unsafe or machine-dependent endurance conversion code, you are almost certainly doing it wrong. http://commandcenter.blogspot.co.uk/2012/04/byte-order-fallacy.html http://commandcenter.blogspot.co.uk/2012/04/byte-order-falla...
- deletes 13y agoThank you for that link. #leaves to check some old code . . . #comes back Apparently my younger self knew what he was doing. ( The conversion is done correctly :shocked: )
- csmithuk 13y agoThat's a great article - thanks for posting.
- mcguire 13y agoSometimes I wonder about Rob. "In fact, C may be part of the problem: in C it's easy to make byte order look like an issue. If instead you try to write byte-order-dependent code in a type-safe language, you'll find it's very hard. In a sense, byte order only bites you when you cheat."
- fanf2 13y ago"endurance"?! Damn you, autocorrect.
- mcguire 13y agoOddly enough, I've spent the last week playing around with type-agnostic garbage collection.