Zig NEWS

Discussion on: Type/pointer cheatsheet

Collapse
 
toxi profile image
Karsten Schmidt

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?

Collapse
 
orent profile image
orent

What is the logic behind this restriction? Something about the representation of non-pointer optionals?

Thread Thread
 
toxi profile image
Karsten Schmidt

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... :)