Is Python type safe?
Skip Montanaro
skip at pobox.com
Tue Mar 16 17:31:11 EST 2004
>> Sorry to follow up to my own post, but unions also create type
>> unsafety.
Roy> Of course you can. Given C's roots as a high level assembly
Roy> language, why would you expect anything else?
Nope. But the user asked if C++ was type safe. The presence of unions
indicates that it's not, at least in some situations.
Roy> I was once asked on an interview how I would tell, inside of a C
Roy> program, if I was on a big endian or a small endian machine. I
Roy> said I'd create a union of a long and a char[4], set the long equal
Roy> to 1, and see which char it showed up in. The interviewer looked
Roy> shocked, thought about it for a while, and finally said something
Roy> like, "yeah, I guess that would work".
Sure. There are plenty of reasons to use unions. They can be a
double-edged sword though.
Skip
More information about the Python-list
mailing list