Message-ID: <37B5D75B.7DB28AC@unb.ca> From: Endlisnis X-Mailer: Mozilla 4.61 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: From Bytes to Int and Char References: <37B466D7 DOT 958F09E5 AT americasm01 DOT nt DOT com> <37B4DFD1 DOT 4D66 AT surfsouth DOT com> <37B57EB0 DOT 492A93AE AT unb DOT ca> <37B5877D DOT 2343 AT surfsouth DOT com> <37B5BA42 DOT 3F05CED2 AT unb DOT ca> <37B5BF52 DOT 5C00 AT surfsouth DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 39 Date: Sat, 14 Aug 1999 20:54:57 GMT NNTP-Posting-Host: 209.226.124.241 X-Trace: news20.bellglobal.com 934664097 209.226.124.241 (Sat, 14 Aug 1999 16:54:57 EDT) NNTP-Posting-Date: Sat, 14 Aug 1999 16:54:57 EDT Organization: Sympatico To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Chris Holmes wrote: > Endlisnis wrote: > > > > But, your code did the same thing, it casted it as a short* (which you stored in a > > temporary variable) and then augmented it with an offset. You code would do the EXACT > > same thing as mine on any and all machines. Both mechanisms were interpreting the int in > > a 'native' way. What I was trying to say, was that if the file was saved in a big-endian > > machine and you were using a little-endian machine... both of our codes would not work. > > Yes, BUT if you RECOMPILED my code with a big-endian compiler, it > would at least in theory produce the right output. My code put the > work for conversion on the compiler's head, so if I moved to a > big-endian compiler, then I wouldn't have to change my code. char*Buff; Your code: short* int_buff = (short*)buff; int val = int_buff[8]; My code; int val = *(short*)(Buff+8); //I don't remember if the index really was '8' but that's not the point. My code, if compiled on a big-endian compiler, would also produce the right output (if the buffer was written by a big-endian program). The only way to make it really endian safe, would be to use one of the POSIX function that comes with tcp/ip libraries which converts local format to big-endian format. It is designed to be portable. -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT HotMail DOT com ICQ: 32959047