www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/14/13:34:44

Message-ID: <37B57EB0.492A93AE@unb.ca>
From: Endlisnis <s257m AT unb DOT ca>
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: <rfXs3.4$bZ1 DOT 1603 AT typhoon01 DOT swbell DOT net> <37B466D7 DOT 958F09E5 AT americasm01 DOT nt DOT com> <37B4DFD1 DOT 4D66 AT surfsouth DOT com>
Lines: 36
Date: Sat, 14 Aug 1999 14:36:35 GMT
NNTP-Posting-Host: 209.226.124.241
X-Trace: news21.bellglobal.com 934641395 209.226.124.241 (Sat, 14 Aug 1999 10:36:35 EDT)
NNTP-Posting-Date: Sat, 14 Aug 1999 10:36:35 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:

> > > char ver, type;
> > > int sz, tz;
> > > sz = file_buffer[6] + file_buffer[7];
> > > is that right?
> >
> >     No.  Here's the right way to do it.  This code is not edian safe.
> > sz = *(short*)(file_buffer+6);
>
>   (sorry... have to say it) They aren't endians, they're native
> arrangements.  Please, be PC with your PC.  <grin>

    I don't know what you are talking about.   The word endian means the native
order of bytes in a multibyte contiguous variable type.

>   One solution (kinda tricky because you need to make sure they are
> stored on a 2 byte boundary or hack around my trick, which is a hack
> itself).
>   Given: void *buffer;
>   make: char *c_buffer=(char *)buffer;
>   make: short *i_buffer=(short *)buffer;
>   then: short i = i_buffer[BYTE_OFFSET / 2];
>   (this should be a little more endian safe)

    I don't see how, because it's doing the exact same thing in a more obsure way.
I was trying to say that if the file was stored on a big-endian machine, then using
a little-endian like DJGPP to read the file in the way I mentioned wouldn't work.

--
     (\/) Endlisnis (\/)
          s257m AT unb DOT ca
          Endlisnis AT HotMail DOT com
          ICQ: 32959047


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019