Mail Archives: djgpp/1999/08/17/15:34:23
George Ryot wrote:
> "Campbell, Rolf [SKY:1U32:EXCH]" <cp1v45 AT americasm01 DOT nt DOT com> wrote:
>
> > I don't understand how your code is any less of a 'hack' than mine. Both are not
> > endian safe. Both will work consistantly on each individual machine (I'm not saying
> > that you could exchange data files and have them work). How is my code 'unsafe'?
>
> Casting between pointers to different types is nearly always unsafe.
It depends what you mean by 'unsafe'. If you look at code, I think you would find
that most pointer casts work fine and that a small minority cause unsafe code.
> The code I posted will solve the original problem (as I understand it)
> and will work the same on *all* implementations except attention is
> required to unsigned values.
[your original code]:
unsigned short sz, tz;
sz = (file_buffer[5] << 8) & file_buffer[6];
tz = (file_buffer[10] << 8) & file_buffer[11];
Your code does solve the original problem. And you know what... I totally missed the fact
that you were forcing big-endian-ness. Oh well, I live: I learn...
--
-Rolf Campbell (39)3-6318
- Raw text -