c - Visual Studio 相当于 Arm #pragma anon_unions

标签 c struct arm keil

Arm“#pragma anon_unions”允许:

typedef struct {
    uint32_t sensorID;
    uint8_t  messageHeader;
    uint8_t  messageID;
    uint16_t payloadLength;
} Header;

typedef struct {
    uint8_t startOfPacket[SERIAL_SOP_SIZE]; 
    Header; // Anonymous.
    uint8_t payload[SIZE];
} Packet;

Packet packet;
packet.messageID = 1; // Referencing member of Header through a Packet.

关于在 VisualStudio 中编译此代码有什么想法吗?

最佳答案

它可以在 Visual C++ 中编译,但是 only in C mode :

A Microsoft C extension allows you to declare a structure variable within another structure without giving it a name. These nested structures are called anonymous structures. C++ does not allow anonymous structures.

关于c - Visual Studio 相当于 Arm #pragma anon_unions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11545041/

相关文章:

c - 我无法理解这种类型转换

c - 提示用户询问输入直到满足条件?

c++ - 我应该在使用 dlopen() 之前先执行 malloc() 吗?

计算结构尺寸

c - 在 CMake 中编译静态 C 库时未生成中间 .obj 文件

c - 什么是执行区域和输入部分的过度对齐?

c - C语言的调度例程和时序要求

c++ - 如果将不正确的参数类型传递给结构初始化器列表,为什么编译器不会生成编译错误?

c++ - 嵌套结构初始化

c++ - 修复关于 C/C++ 和寄存器访问的知识差距