#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是什么意思?
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 iscout<<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!";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.