4 ms·
As an embedded firmware developer, I really wish there was a way to outright disallow implicit type conversions in C source code. You'd have to exclude librarie
by falcrist 7y ago
As an embedded firmware developer, I really wish there was a way to outright disallow implicit type conversions in C source code. You'd have to exclude libraries, but I'm creating "typedef enum" to show what I'm doing AND help make sure I don't somehow screw it up. If all of those typedefs are interchangable with each other (and ints and chars), I lose out on part of the functionality.
- dllthomas 7y agoTo get nominal typing in C, wrap things in a struct. There shouldn't be any performance overhead (the generated code should often, if not always, be unchanged), and the boilerplate can be manageable (and you can unpack things locally when it starts to get too messy). See https://dlthomas.github.io/using-c-types-talk/slides/slides.html https://dlthomas.github.io/using-c-types-talk/slides/slides.... (... which I should really turn into a blog post or something)
- heinrich5991 7y agoSome ABIs pass structs containing a single element differently (and in a less performant way) than primitive data types.
- dllthomas 7y agoYou should always be aware of the details of whatever platform you're targeting, to be sure. That said, can you name a few that work this way? If I've worked on such a platform, it's been a long while.
- heinrich5991 7y agoApparently ARM64 does this for return values. I remembered the `#[repr(transparent)]` proposal that precisely tackled this problem for Rust: [RFC 1758](https://github.com/rust-lang/rfcs/blob/de0917dca549694fffbe30f7951a938417f27d27/text/1758-repr-transparent.md https://github.com/rust-lang/rfcs/blob/de0917dca549694fffbe3...).
- dllthomas 7y agoThanks, I'll dig in! Is this limited to floating point? That doesn't surprise me nearly as much.