此代码没有像我预期的那样返回,标识符应为0xABC.有可能修复此问题吗?
#include <stdio.h>
#include "stdint.h"
typedef struct {
union {
struct {
uint8_t address: 8;
uint16_t identifier: 16;
};
uint32_t fullAddress;
};
} isotpAddress_t;
int main() {
isotpAddress_t myAddress;
myAddress.fullAddress = 0xABCDE;
printf("Address: 0x%02X\n", myAddress.address); // 输出: Address: 0xDE
printf("Identifier: 0x%04X\n", myAddress.identifier); // 输出: Identifier: 0x000A but want 0x0ABC
return 0;
}
输出:
> Address: 0xDE
> Identifier: 0x000A