简体   繁体   English

win64 结构中变量的顺序重要吗?

[英]Does order of variables in struct for win64 matter?

So I was working with socket programming in windows and I came upon this struct.所以我在 windows 进行套接字编程时遇到了这个结构。

#define WSADESCRIPTION_LEN  256
#define WSASYS_STATUS_LEN   128

typedef struct WSAData {
    WORD        wVersion;
    WORD        wHighVersion;
#ifdef _WIN64
    unsigned short  iMaxSockets;
    unsigned short  iMaxUdpDg;
    char        *lpVendorInfo;
    char        szDescription[WSADESCRIPTION_LEN+1];
    char        szSystemStatus[WSASYS_STATUS_LEN+1];
#else
    char        szDescription[WSADESCRIPTION_LEN+1];
    char        szSystemStatus[WSASYS_STATUS_LEN+1];
    unsigned short  iMaxSockets;
    unsigned short  iMaxUdpDg;
    char        *lpVendorInfo;
#endif
} WSADATA, *LPWSADATA;

You can see the struct members are same for each condition only the placement is different.您可以看到每个条件的结构成员都相同,只是位置不同。

Why actually is this done?为什么实际上这样做? Is it relevant to new programmers like me?它与像我这样的新程序员有关吗?

and can I just carry on my tasks without any worry or should I look upon this more seriously?我可以毫无顾虑地继续我的任务,还是应该更认真地看待这件事?

Does order of variables in struct for win64 matter? win64 结构中变量的顺序重要吗?

Only for padding.仅用于填充。

Is it relevant to new programmers like me?它与像我这样的新程序员有关吗?

Don't think about it.别想了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM