Bouncing off another topic mentioned in the latest podcast: union types. Yes, C had them but the first time I was exposed to them was in Pascal, and the discussion on the podcast reminded me of an awesome hack that blew my mind a very long time ago.
Pascal was well known to be very strict and safe. Among other things, it didn't let you access the memory directly, which was a big deal in the 8 bit era where memory protection was a distant dream and PEEK and POKE were how you wrote games. And then, one day, somebody found a way to address the memory using standard Pascal. Here is the trick (from memory, so it's probably not quite correct): type b = record x : array[1..65536] of ^integer; y : integer; end; This declares a union type that is made of either an array of 65k pointers to integers or a single integer. Then you initialize this record in its "x" side with the memory address you want to peek and you access it by using the "x" side of the record. It took me months to understand what this code did, but what a revelation it was when it finally clicked... By the way, these types are formally known as "sum types" (Either is one of them). -- Cédric -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to javaposse@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.