Well, here's an interesting twist of these two things: Let &T be a pointer to object, never NULL, can't be incremented, and thus "always safe" if allocated by Felix. Now consider:
union cptr[T] = NULL | Object of &T; So now, this kind of pointer can be NULL but you can't dereference it. You have to use a match or let binding: val cp: cptr[int] = .... let Object ?p = cp in *p There. That's safe. If cp is NULL, you get a match failure. The interesting thing is that C's NULL is also NULL. A C pointer can be converted to an Object of &T by setting the low bit. The representation fo cptr[T] uses one machine word: it's a pointer. Of course: cptr[t] === opt[T] What's interesting here is the idea of yet another special representation, which would work for list and some cases of opt as well: test directly for 0 or non-zero pointer. This saves the funny bit. It only works for two cases, one of which is a const constructor, the other a constructor with pointer (or function) argument. So, we get these amazing benefits: * 100% compatible with heap allocated C pointers * 100% safety via enforced dynamic check for NULL * high efficiency by allowing "non-null-ness" to propagate via static type system Issues: * won't work for arbitrary char*, since that can point to an odd byte. Most all other pointers are aligned to at least two bytes * we do assume 16 byte alignment of functions (even on 32 bit machines). * assume correct encoding of C functions -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language