请问这个c++是什么意思
高洛峰
高洛峰 2017-04-17 13:42:30
0
5
630
#define VMSDISPOSITION_SIZE    31
typedef struct _VMSDISPOSITION
{
    BYTE MajorVersion;
    BYTE MinorVersion;
    VMSDATE BuildDate;
    WORD DisplayWidth;
    WORD DisplayHeight;
    BYTE PrimaryColors;
    BYTE BitsPerColor;
    DWORD TotalDiskSpace;
    DWORD FreeDiskSpace;
    VMSDATETIME LastResetTime;
}VMSDISPOSITION;

我知道这是一个结构体 #define VMSDISPOSITION_SIZE 31 这句是什么意思 还有VMSDISPOSITION_SIZE 和31是什么意思?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(5)
伊谢尔伦
#define VMSDISPOSITION_SIZE    31

In short, this is actually an assignment operation, that is to say VMSDISPOSITION_SIZE=31, and it has a more awesome name called macro definition, or you can also understand it as defining a constant. What is the difference between this macro definition and assignment? When the compiler compiles this code, it will automatically replace VMSDISPOSITION_SIZE with 31. If there is cout<<VMSDISPOSITION_SIZE, the compiler will automatically replace VMSDISPOSITION_SIZE with 31.

And macro definitions are not only limited to the function of defining numbers, but can also define statements, such as #define VMSDISPOSITION_SIZE cout<<"hello world!";, then when the compiler encounters VMSDISPOSITION_SIZE, it will automatically replace VMSDISPOSITION_SIZE with cout<< "hello world!";

PHPzhong
#define VMSDISPOSITION_SIZE 31

is a macro definition, which means that in the following code, all VMSDISPOSITION_SIZE will be replaced by 31 in the preprocessing stage.
That is, you can regard the VMSDISPOSITION_SIZE that appears later as 31

伊谢尔伦

According to the literal meaning

sizeof(VMSDISPOSITION) = 31, it is used for convenience, so define

define VMSDISPOSITION_SIZE 31

大家讲道理

A macro is defined to make VMSDISPOSITION_SIZE equal to 31. In the future, where 31 is needed, use VMSDISPOSITION_SIZE instead. If you need to modify it, just modify the value of this macro directly. Even if there are a lot of codes, there will be no missing items, making it easy to use. This value is a constant and cannot be changed in the program.

迷茫

Macro definition
is equivalent to equivalent substitution in mathematics.
Read more books on a daily basis.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template