Specifies alignment.
Syntax
Type typename Field = { 1 | 2 | 4 }
...
End Type
Description
Note: The following information is not complete, FB follows the GCC padding rules, which these next sentences do not fully describe. The source file symb-struct.bas of the compiler shows the exact method.
A
Type variable has its fields aligned depending on complex rules.
Field modifies the default padding byte limit for data fields alignment to one byte (
Field 1) or two bytes (
Field 2) or four bytes (
Field 4). The data fields are aligned by the compiler at their natural boundaries, and it does this through padding, inserting as much bytes as necessary up to the padding limit.
This helps FreeBASIC maintain compatibility with structures created in other languages.
Example
Type bitmap_header Field = 1
bfType As UShort
bfsize As UInteger
bfReserved1 As UShort
bfReserved2 As UShort
bfOffBits As UInteger
biSize As UInteger
biWidth As UInteger
biHeight As UInteger
biPlanes As UShort
biBitCount As UShort
biCompression As UInteger
biSizeImage As UInteger
biXPelsPerMeter As UInteger
biYPelsPerMeter As UInteger
biClrUsed As UInteger
biClrImportant As UInteger
End Type
Dim bmp_header As bitmap_header
'Open up bmp.bmp and get its header data:
'Note: Will not work without a bmp.bmp to load . . .
Open "bmp.bmp" For Binary As #1
Get #1, , bmp_header
Close #1
Print bmp_header.biWidth, bmp_header.biHeight
Sleep
Dialect Differences
- In the -lang qb dialect, the Field alignment is always one, no padding is ever done, as in QB.
Differences from QB
- In QB Field was used to define fields in a file buffer at run time. This feature is not implemented in FB, so the keyword has been redefined. To define fields in a file buffer, Types must be used.
See also