Home  >  Q&A  >  body text

请问这个c++是什么意思

#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是什么意思?

高洛峰高洛峰2714 days ago578

reply all(5)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:44:30

    #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!";

    reply
    0
  • PHPz

    PHPz2017-04-17 13:44:30

    #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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:44:30

    According to the literal meaning

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

    define VMSDISPOSITION_SIZE 31

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:44:30

    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.

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:44:30

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

    reply
    0
  • Cancelreply