55.7 연습문제에 대한 질문이 있습니다!
, 노 농님이 작성#include <stdio.h>
struct DeviceOption {
union {
unsigned long long option;
struct {
unsigned char boot[4];
unsigned char interrupt[2];
unsigned char bus[2];
};
};
};
int main()
{
struct DeviceOption opt;
opt.boot[0] = 0x01;
opt.boot[1] = 0x02;
opt.boot[2] = 0x03;
opt.boot[3] = 0x04;
opt.interrupt[0] = 0x05;
opt.interrupt[1] = 0x06;
opt.bus[0] = 0x07;
opt.bus[1] = 0x11;
printf("0x%llx\n", opt.option);
return 0;
}공용체를 통해 익명 구조체 속 멤버들(unsigned char boot, interrupt, bus)이 unsigned long long option 멤버에 병합된 것은 이해가 됩니다.
그런데 제가 궁금한 점은, 이후에 구조체 DeviceOption의 변수 opt.option을 printf로 출력했을 때 "어떻게 16진수들이 하나로 이어져 나올 수 있는지"입니다.
공용체에 의해 익명 구조체 속 멤버들(세가지 배열들)이 변수 option에 병합될 때 어떤 모습인지 알 수 있을까요..??
Re: 55.7 연습문제에 대한 질문이 있습니다!
, 도장_ 관리자님이 작성https://dojang.io/mod/forum/discuss.php?d=1920
이전 질문을 참고하세요.
연습문제의 코드를 완성하고, Visual Studio에서 잘 동작하는 것을 확인했으면 C 언어 온라인 시각화에서 시각화해서 눈으로 확인하세요.
포럼 상단 고정 글입니다. 고정 글은 천천히 한 번 보면 좋습니다.