www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/07/23:56:10

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199606080336.AA129144998@relay1.geis.com>
Date: Sat, 8 Jun 96 03:14:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: bmp file format

Reply to message 3580425    from MKOCH AT CHEMIE. on 06/07/96  6:33AM


>I want to write a part of the graphic screen into a .bmp file. I changed the
>variable formats, I have found in a script, from 'DWORD' to 'unsigned long'
>and from 'WORD' to 'unsigned short', which should have the same length in
bytes.
>
>I found, that the bytes within the variables are disordered in the file and no
>graphic program can read my bmp files!
>
>Can anyone help me, to fix this problem?

DJGPP, as a 32-bit compiler, aligns fields of structs on 4-byte boundaries.
Append "__attribute__((packed))" (sans quotes) between the closing
brace and the semicolon of the struct definition.  For more information about
alignment and packing, look in the gcc docs.

BTW, you could simply have done a define or typedef of DWORD and WORD
within the program, instead of rewriting the code.  Also keep in mind that
in a 32-bit compiler, a word _is_ 4 bytes long, not 2.  The terms 'word' and
'dword' can be misleading.
John

- Raw text -


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