4 ms·
I’m probably the only one who gets Variable Length Arrays and Flexible Length Arrays mixed up. But if I’m not… https://en.wikipedia.org/wiki/Flexible_array_mem
by SV_BubbleTime 5y ago
I’m probably the only one who gets Variable Length Arrays and Flexible Length Arrays mixed up.
But if I’m not… https://en.wikipedia.org/wiki/Flexible_array_member https://en.wikipedia.org/wiki/Flexible_array_member
FLA is the one where the undefined size array is put at the end of a struct and you carefully access it beyond the size of the struct itself. Usually malloc as you would with a VLA.
1. I’m sure Rust people really hate this idea.
2. I’m just realizing you could be really reckless point a FLA to a VLA used as a buffer, maybe I’ll set that up next time I’m interviewing.
- CodesInChaos 5y ago> 1. I’m sure Rust people really hate this idea. Rust has unsized types, like slices. Such types can't be passed by value and pointers to such types consist of two words (address and length for slices). You can put an unsized type at the end of a struct, resulting in an unsized struct. Using a slice as the last member is equivalent to a flexible array member in C. Unfortunately they're barely usable in the current state, since there is no good way to construct such a struct.
- SV_BubbleTime 5y ago>You can put an unsized type at the end of a struct, resulting in an unsized struct. Using a slice as the last member is equivalent to a flexible array member in C. News to me! I figured it was inherently a little "unsafe" and Rust's thing in mem safety. Good to know! >Unfortunately they're barely usable in the current state, since there is no good way to construct such a struct. Ok, well, now that's just bizarre, but I assume there is a good reason. I'll get on Rust when it's "official" somewhere for embedded. Until then, a strange and mystical shadow in the forest for me.