【发布时间】:2021-04-09 14:32:21
【问题描述】:
我想用以下值初始化以下结构的ColourModelBlock:
extension_size = 4model = 0red = 0green = 0blue = 0
typedef struct {
int extension_size;
ColourModelData ext;
} ColourModelBlock;
typedef struct {
unsigned int model;
union {
struct {
int red; /* % */
int green; /* % */
int blue; /* % */
} rgb;
struct {
int cyan; /* % */
int magenta; /* % */
int yellow; /* % */
int key; /* % */
} cmyk;
struct {
int hue; /* angle (degrees) */
int saturation; /* % */
int value; /* % */
} hsv;
char bytes[16];
int words[4];
} data;
} ColourModelData;
任务看起来很简单,但我尝试直接设置值(这适用于 extension_size 和 model,但我不知道如何设置联合值)或使用 memcpy 的 int数组。
但我对 C 很陌生,所以我可能把它搞砸了。
【问题讨论】:
标签: c struct initialization union