5 ms·
I've used this trick (unions within structs) for decades. You can parse very quickly, but your code will not necessarily be portable. It's a perfect solution
by anonymousiam 2y ago
I've used this trick (unions within structs) for decades. You can parse very quickly, but your code will not necessarily be portable. It's a perfect solution if your application will only be run on the hardware you're developing on.
- atiedebee 2y agoWhy are unions within structs not portable?
- cantrecallmypwd 2y agoUndefined padding and alignment.
- Keyframe 2y agoyou can do explicit padding and you can force alignment; latter might be compiler specific until C11 at least. You can always check for the struct layout as an assert.. it's doable.
- atiedebee 2y agoThat doesn't really matter for sum types as used in this blog, does it? As long as you're not serialising the struct or accessing it through pointers of different types it ought to work anywhere.
- cantrecallmypwd 2y agoTemporary, in-memory representation of an AST generally doesn't need to be serialized or passed outside the process in this use case.