Maybe slightly unclear wording from my side on that extern section! I meant to say: optionals are only supported if in pointer form, but not as optional values, i.e. *?u8 or ?*u8 is supported, but ?u8 isn't. That didn't mean to imply that all pointers must be optional! Normal pointers are supported of course... Makes sense?
I'd think it's because there's no concept of optional values in C, yet optional pointers can be represented in the same amount of space (using 0 as indicator for a null pointer), whereas optional non-pointer values take up extra bytes, e.g. a ?u8 is actually 2 bytes, a ?u16 is 4 bytes, a ?u32 is 8 bytes...
An argument could be made that by that logic slices shouldn't be supported either (but they are), so I really don't know the reasons... :)
In the extern struct examples, isn’t the second example a non-optional pointer? (to an optional u8)
IIUC, it does not meet the requirement for pointers to be optional
Maybe slightly unclear wording from my side on that extern section! I meant to say: optionals are only supported if in pointer form, but not as optional values, i.e.
*?u8
or?*u8
is supported, but?u8
isn't. That didn't mean to imply that all pointers must be optional! Normal pointers are supported of course... Makes sense?What is the logic behind this restriction? Something about the representation of non-pointer optionals?
I'd think it's because there's no concept of optional values in C, yet optional pointers can be represented in the same amount of space (using
0
as indicator for anull
pointer), whereas optional non-pointer values take up extra bytes, e.g. a?u8
is actually 2 bytes, a?u16
is 4 bytes, a?u32
is 8 bytes...An argument could be made that by that logic slices shouldn't be supported either (but they are), so I really don't know the reasons... :)
Just edited that section of the post, hopefully clarifying things... Thanks for pointing it out!