Is Python type safe?
Carl Banks
imbosol at aerojockey.invalid
Tue Mar 16 21:19:12 EST 2004
Roy Smith wrote:
> I was once asked on an interview how I would tell, inside of a C
> program, if I was on a big endian or a small endian machine. I said I'd
> create a union of a long and a char[4], set the long equal to 1, and see
> which char it showed up in. The interviewer looked shocked, thought
> about it for a while, and finally said something like, "yeah, I guess
> that would work".
>
> To this day, I have no idea what other plan he had in mind.
Here's my guess:
long i = 0;
*(short*)&i = 1;
if (i == 1) { printf("It's whatever one Intel uses.\n"); }
else { printf("It's the other one.\n"); }
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
More information about the Python-list
mailing list