🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

A data type question....

Started by
7 comments, last by Mike 24 years, 5 months ago
I know that this is the correct structer for the bitmap header, but...

struct BITMAPFILEHEADER
{
    WORD    bfType; 
    DWORD   bfSize; 
    WORD    bfReserved1; 
    WORD    bfReserved2; 
    DWORD   bfOffBits; 
};
 
...makes use of WORD and DWORD. I don''t want to use these. What are the equivalents to WORD and DWORD in thers of int, long, short, char, unsigned, signed, and so on. Thanks
Advertisement
I don''t remember exactly what they are off the top of my head. try searching Windef.h in the windows SDK for DWORD and you should find the typedef.


_________________Gecko___

_________________Gecko___Gecko Design
If I remember correctly BYTE is 1 byte(duh), WORD is 2 bytes, and DWORD is 4 bytes...so int is the equivalent of WORD(probably unsigned int actually) and [unsigned] long would be the equivalent of DWORD.
Chris
Not quite, an int is 4 bytes.
The below struct properly loads the header:

struct BITMAPFILEHEADER{    WORD    bfType;     DWORD   bfSize;     WORD    bfReserved1;     WORD    bfReserved2;     DWORD   bfOffBits; }; 


The below definition of the struct does not:

struct BITMAPFILEHEADER{    unsigned short	bfType;     unsigned long	bfSize;     unsigned short  bfReserved1;     unsigned short  bfReserved2;     unsigned long   bfOffBits; }; 


Why?
Sorry I can''t give you a straight answer or reasoning but try doing a sizeof() for WORD, DWORD, unsigned short and unsigned long to find out their byte sizes according to _your_ compiler.
All compilers are different and there are no guarentees that the type sizes are identical on different compilers.

Then you''ll know how to load that damn header
a DWORD is always 4 bytes - an unsigned long int
a WORD is always 2 bytes - an unsigned short int
a BYTE is always 1 byte - an unsigned char
If it is reading in the info wrong into the header, it is probably due to the fact that C and C++ pad the structures to WORD align the data in the structure. Tou can use the long int and whatever else data type as long as you do separate reads for each member, i.e.

read(file, struct.member1, sizeof(data type));
read(file, struct.member2, sizeof(data type));

and so on...

sizeof(struct) does not always return the sum of the data types of its members

Edited by - rroach on 1/19/00 2:55:39 PM
What''s wrong with using the WORDs and DWORDs?

This topic is closed to new replies.

Advertisement