delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/04/12:34:16

From: bywale-t AT zszosw DOT petex DOT com DOT pl (Tomasz Bywalec)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: New Moron on the Block :)
Date: 4 Oct 2001 09:19:39 -0700
Organization: http://groups.google.com/
Lines: 46
Message-ID: <8af9182.0110040819.732e3eb0@posting.google.com>
References: <34539894 DOT 0110031004 DOT 1133f1ea AT posting DOT google DOT com>
NNTP-Posting-Host: 195.164.188.161
X-Trace: posting.google.com 1002212380 24526 127.0.0.1 (4 Oct 2001 16:19:40 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: 4 Oct 2001 16:19:40 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

pouzzler AT aol DOT com (pouzzler) wrote in message news:<34539894 DOT 0110031004 DOT 1133f1ea AT posting DOT google DOT com>...

> I have tried to overload _read, so that it will read WORDS, DWORDS or
> BYTES like that
> 
> _read(WORD Word)
> {
> char buffer[2];
> int blah;
> _read(blah, buffer, 2);
> Word = 256*buffer[0]+buffer[1];
> }
> 
> Now, since a word is two bytes, the formula should do it....
> 
> However it is both ugly-looking (and ugliness rarely comes out good in
> our cruel world)... and doesn't work.

Well, I'm not sure, but maybe at least one of these below will work:

1. If you want to change contents of parameters parsed to function
   you should declare them as pointers (C) or references (C++ - 
   and I'm not 100% sure that these things are called "references :-)
   Like this:

   read( WORD *Word )
   ...
   *Word = 256*buffer[0]+buffer[1]

   OR in C++ you can do it:

   read( WORD &Word )
   ...
   Word = 256*buffer[0]+buffer[1] // <- No & before Word in this line

2. Maybe bytes in BMPs Words aren't organized in that way:
   Word = 256*buffer[0]+buffer[1]
 
   but like that:
   Word = 256*buffer[1]+buffer[0]

Some private-opinions at end : I don't think that your code is ugly. 
Anyway, I think, that code doesn't need to look nice - it just have 
to be short and fast :-)

And sorry for my poor english :-)

- Raw text -


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