Skip to content

FIELD


指定字段对齐方式。

语法

vb
Type|Union typename Field = { 1 | 2 | 4 }

...

End Type|Union

说明

Field 可用于比默认布局更紧密地打包 TypeUnion。最常用的值是 Field = 1,它会使 TypeUnion 尽可能紧密地打包,字段之间以及 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

Sleep

end GeSHi

方言差异

  • -lang qb 方言中,若未指定其他 Field 值,编译器默认假设 Field = 1,使所有结构像 QB 一样紧密打包,不添加填充。

与 QB 的区别

  • 在 QB 中,Field 用于在运行时定义文件缓冲区中的字段。此功能在 FB 中未实现,因此该关键字被重新定义。若要定义文件缓冲区中的字段,必须使用 Type

另请参阅

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系