3 ms·
C. typedef struct{int filled; union{void* data;} val;} maybe;
by heartbeats 7y ago
C.
typedef struct{int filled; union{void* data;} val;} maybe;
- marcosdumay 7y agoHow does that fail at compile time if you try to read a value when there is none?
- madmax96 7y agoSome of Dawson Engler’s work helps solve this problem, starting around [1]. In that, he shows us how to write custom compiler rules in a high-level language. These rules are sufficient to enforce that maybe type. In another paper, Engler (or one of his several talented students, can’t remember now) shows us how to automatically infer many of these rules. [1] https://web.stanford.edu/~engler/mc-osdi.pdf https://web.stanford.edu/~engler/mc-osdi.pdf
- heartbeats 7y agoIf you try to use it val directly, it fails. You must unpack it first. To do something like x.get() in Scala when x is empty is a runtime error, not a compile-time error.
- deleted 7y ago[deleted]