FIELD
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgField
- 最后更新: 2017-04-15
指定字段对齐方式。
语法
vb
Type|Union typename Field = { 1 | 2 | 4 }
...
End Type|Union说明
Field 可用于比默认布局更紧密地打包 Type 或 Union。最常用的值是 Field = 1,它会使 Type 或 Union 尽可能紧密地打包,字段之间以及 Type 末尾不添加任何填充字节。Field 只能用于减小字段对齐粒度,不能用于增大。若要添加填充字节,可以改用带有适当成员的 Union。
示例
start GeSHi
vb
Type bitmap_header Field = 1
bfType As UShort
bfsize As ulong
bfReserved1 As UShort
bfReserved2 As UShort
bfOffBits As ulong
biSize As ulong
biWidth As ulong
biHeight As ulong
biPlanes As UShort
biBitCount As UShort
biCompression As ulong
biSizeImage As ulong
biXPelsPerMeter As ulong
biYPelsPerMeter As ulong
biClrUsed As ulong
biClrImportant As ulong
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
Sleepend GeSHi
方言差异
- 在 -lang qb 方言中,若未指定其他
Field值,编译器默认假设Field = 1,使所有结构像 QB 一样紧密打包,不添加填充。
与 QB 的区别
- 在 QB 中,
Field用于在运行时定义文件缓冲区中的字段。此功能在 FB 中未实现,因此该关键字被重新定义。若要定义文件缓冲区中的字段,必须使用Type。
另请参阅
TypeUnion- 结构体打包/字段对齐
返回 目录