一个奇怪的问题,关于type大小的

cai12345 2003-10-19 07:01:04
有一个type
type T
a as integer
b as long
end type

dim a as T
结果len(a)=6
lenb(a)=8
请问为什么会多出两个字节呢,如果我要用一个二进制数组来储存这个type,
dim b() as byte
应该是
redim b(len(a)) as byte
copymemory b,a,len(a)
还是
redim b(lenb(a)) as byte
copymemory b,a,lenb(a)
...全文
33 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cai12345 2003-10-20
  • 打赏
  • 举报
回复
比如
type a
a as byte
b as integer
c as long
end type
那么,我把结构a用winsock传到另一个用c写的程序,c的struct 是不是应该是
struct
{
long a;
long b;
long c;
}
呢?
subzero 2003-10-19
  • 打赏
  • 举报
回复
汗。。。还是说错了
应该是大力水手说的对,自动向最长的变量对齐,如果是long,则被4整除,以此类推
subzero 2003-10-19
  • 打赏
  • 举报
回复
错了,不是2的n次,应该是被2整除
subzero 2003-10-19
  • 打赏
  • 举报
回复
应该用lenb才能得到正确结果
type类型会自动补整到2的n次

比如:
type a
a as integer
b as integer
end type
这个len跟lenb都得到4

type a
a as long
b as integer
end type
这个len是3,lenb是4

type a
a as byte
b as integer
c as long
d as single
end type
这个len是11,lenb是12

kmzs 2003-10-19
  • 打赏
  • 举报
回复
什么。。。!!!
boywang 2003-10-19
  • 打赏
  • 举报
回复
一般来说32位操作系统对于long型的数据处理最快,楼主的定义在编译器编译后自动对齐了。
也就是说b自动对齐到4倍数的地址上了。

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧