Mail Archives: djgpp/2001/10/04/12:34:16
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 -