Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Tagged unions would be, except they aren't first class in C.

For the originally stated example, 'declare a variable, set it to 5 (number), and then set it to the "hello" (string)', a plain union is just fine.

> The best analogy here would probably be OCaml polymorphic variants

It would be, except OCaml is not C.

> It is not, though, because - unlike JavaScript - the fact that everything is a reference to object

Evidently, references and pointers are not the same thing, hence it is an implementation detail whether references correspond to pointers.

> and each object has a unique identity

Which doesn't necessarily have anything to do with their address. It's an opaque value guaranteed to be unique for an object for the duration of its lifetime.

Meanwhile, C pointer values aren't necessarily unique for different objects. For example, a pointer to a struct with one or more fields shares value with a pointer to its first field. It's only once you factor in type that pointers uniquely identify a particular object, so they don't exactly correspond to Python's object identity.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: