From: "Campbell, Rolf [SKY:1U32:EXCH]" Newsgroups: comp.os.msdos.djgpp Subject: Re: From Bytes to Int and Char Date: Tue, 17 Aug 1999 11:16:22 -0400 Organization: Nortel Networks Lines: 31 Message-ID: <37B97CC6.7E054E7F@americasm01.nt.com> References: <37B466D7 DOT 958F09E5 AT americasm01 DOT nt DOT com> <37B4DFD1 DOT 4D66 AT surfsouth DOT com> <37B57EB0 DOT 492A93AE AT unb DOT ca> <37ba82f5 DOT 7514501 AT news DOT clara DOT net> <37B82AAA DOT E7223AB1 AT americasm01 DOT nt DOT com> <37bd890c DOT 14677884 AT news DOT clara DOT net> NNTP-Posting-Host: bmerhc00.ca.nortel.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (X11; I; HP-UX B.10.20 9000/712) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com George Ryot wrote: > "Campbell, Rolf [SKY:1U32:EXCH]" 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