delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/08/16:01:38

Message-ID: <35536390.4745DE24@sobieski.ml.org>
Date: Fri, 08 May 1998 21:57:04 +0200
From: Archee/CoNTRACT <01dsolt AT sobieski DOT ml DOT org>
Reply-To: soltesz AT hotmail DOT com
Organization: School
MIME-Version: 1.0
To: WT <gnatwt AT mailexcite DOT com>
CC: djgpp AT delorie DOT com
Subject: Re: Problem with integer declaration?
References: <354AB827 DOT 8EE19C9D AT mailexcite DOT com>

hi !

The problame is:
GCC alignes data. GCC produces long aligned data.
If you have a short, it will allocate 4 bytes.
And it will use only the first two bytes of the 4 byte allocated in the
structure.

But if you have two shorts, it will put them in ONE long.

So totalmemory and oem_software_rev will be in ONE long.
but vbe version will use 4 bytes.

 unsigned char reserved[222] will lose two bytes space.

Pentium CPU can run faster if you use long aligned data.
I would recommend to lose some memory and use long aligned data.

WT wrote:

> I am trying to write a short program to detect VESA VBE and output
> information about the video card. I declared a struct of 512 bytes to be
> used as a buffer for vbe_info_block. The strange thing is that when I
> printed sizeof(vbe_info_block) it gave me 516 bytes instead of 512. I am
> sure my struct is correct because I've checked it many times. This is
> how the struct is declared :
>
> typedef
>   struct {
>     unsigned int vbe_signature; /* VBE Signature */

4

>     unsigned short vbe_version; /* VBE Version */

8

>     unsigned int oem_string_ptr; /* Pointer to OEM info */

12

>     unsigned int capabilities; /* Capabilities of graphics controller */

16

>
>
>     unsigned int video_mode_ptr; /* Pointer to VideoModeList */

20

>     unsigned short total_memory; /* Number of 64kb memory blocks */

22

>     /* Added for VBE 2.0 */
>     unsigned short oem_software_rev; /* VBE implementation Software

24

> revision */
>     unsigned int oem_vendor_name_ptr; /* Pointer to Vendor Name String

28

> */
>     unsigned int oem_product_name_ptr; /* Pointer to Product Name String

32

> */
>     unsigned int oem_product_rev_ptr; /* Pointer to Product Revision

36

> String */
>     unsigned char reserved[222]; /* Reserved for VBE implementation

260

> scratch area */
>     unsigned char oem_data[256]; /* Data Area for OEM Strings */

516

I won ! :-))

>   } vbe_info_block;
>
> Could it be something wrong with the int declaration? Please help!



- Raw text -


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