在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
delphi枚举类型长度默认为2个字节(单字),而在C中枚举为4个字节(双字),如果需要跨这两个平台编程,传输结构时会由于数据长度不一造成灾难。 经过查找资料,原来delphi可以通过{$Z+} {$Z-} {$Z1} {$Z4} 等宏设置枚举类型的长度,小至1个字节,大至4个字节。 官方说明如下: The $Z directive controls the minimum storage size of Delphi enumerated types. An enumerated type is stored as an unsigned byte if the enumeration has no more than 256 values, and if the type was declared in the {$Z1} state (the default). If an enumerated type has more than 256 values, or if the type was declared in the {$Z2} state, it is stored as an unsigned word. Finally, if an enumerated type is declared in the {$Z4} state, it is stored as an unsigned double word. The {$Z2} and {$Z4} states are useful for interfacing with C and C++ libraries, which usually represent enumerated types as words or double words. Note: Note: For backwards compatibility with early versions of Delphi and CodeGear Pascal, the directives {$Z-} and {$Z+} are also supported. They correspond to {$Z1} and {$Z4}, respectively. 例子如下: http://www.delphibasics.co.uk/RTL.asp?Name=$Z Example code : Various enum type sizes type TCars1 size = 1 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论