gpt4 book ai didi

c - 将结构数组嵌套到另一个结构中

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:42 25 4
gpt4 key购买 nike

我正在尝试创建一个包含结构数组的结构。

到目前为止我的代码(只剪成两个字形)

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

typedef struct glyph_t{
uint16_t width;
uint16_t length;
uint16_t *data;
} glyph_t;

typedef struct font_t{
uint8_t height;
glyph_t glyphs[2];
} font_t;


// '9' character
const uint16_t glyph_0_data[] = {
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0xc318,0xef7b,0x79ce,0x7def,0xbef7,0xfbde,0x34a5,0x2842,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x2842,0x7def,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf39c,0x2000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x6529,0xbef7,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x9294,0x0000,0x0000,0x0000,
0x0000,0x0000,0x18c6,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xe739,0x0000,0x0000,
0x0000,0xc739,0xffff,0xffff,0xffff,0xffff,0x34a5,0x0421,0x6108,0x8a52,0x5def,0xffff,0xffff,0xffff,0x96b5,0x0000,0x0000,
0x0000,0x718c,0xffff,0xffff,0xffff,0x79ce,0x0000,0x0000,0x0000,0x0000,0x0842,0xffff,0xffff,0xffff,0xdfff,0x8210,0x0000,
0x0000,0xbad6,0xffff,0xffff,0xffff,0x4d6b,0x0000,0x0000,0x0000,0x0000,0x0000,0x59ce,0xffff,0xffff,0xffff,0xaa52,0x0000,
0x2000,0xdfff,0xffff,0xffff,0xffff,0x6529,0x0000,0x0000,0x0000,0x0000,0x0000,0xef7b,0xffff,0xffff,0xffff,0x518c,0x0000,
0x2421,0xffff,0xffff,0xffff,0xffff,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x694a,0xffff,0xffff,0xffff,0xb6b5,0x0000,
0xa631,0xffff,0xffff,0xffff,0x9ef7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8631,0xffff,0xffff,0xffff,0xdbde,0x0000,
0xe739,0xffff,0xffff,0xffff,0x5def,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xe318,0xffff,0xffff,0xffff,0xbef7,0x0000,
0xe739,0xffff,0xffff,0xffff,0x9ef7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xc318,0xffff,0xffff,0xffff,0xffff,0x4108,
0x6529,0xffff,0xffff,0xffff,0xffff,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8210,0xffff,0xffff,0xffff,0xffff,0xa210,
0x8210,0xffff,0xffff,0xffff,0xffff,0x6529,0x0000,0x0000,0x0000,0x0000,0x0000,0x4108,0xffff,0xffff,0xffff,0xffff,0xe318,
0x0000,0x3ce7,0xffff,0xffff,0xffff,0xcf7b,0x0000,0x0000,0x0000,0x0000,0x0000,0x6108,0xffff,0xffff,0xffff,0xffff,0x0421,
0x0000,0x34a5,0xffff,0xffff,0xffff,0x5def,0xc318,0x0000,0x0000,0x0000,0x0000,0x8210,0xffff,0xffff,0xffff,0xffff,0xc318,
0x0000,0x494a,0xffff,0xffff,0xffff,0xffff,0xdbde,0x694a,0x6108,0x6108,0x0842,0x75ad,0xffff,0xffff,0xffff,0xffff,0x6108,
0x0000,0x0000,0x59ce,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x0000,
0x0000,0x0000,0x8631,0x9ef7,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x9ef7,0x0000,
0x0000,0x0000,0x0000,0x0842,0x5def,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x59ce,0x0000,
0x0000,0x0000,0x0000,0x0000,0xa210,0x1084,0x9ad6,0x9ef7,0x9ef7,0xbad6,0x9294,0x55ad,0xffff,0xffff,0xffff,0x34a5,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x75ad,0xffff,0xffff,0xffff,0xef7b,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1ce7,0xffff,0xffff,0xffff,0x0842,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8631,0xffff,0xffff,0xffff,0x9ef7,0x2000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x718c,0xffff,0xffff,0xffff,0x75ad,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xc318,0xbef7,0xffff,0xffff,0xffff,0x694a,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x75ad,0xffff,0xffff,0xffff,0x9ad6,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x718c,0xffff,0xffff,0xffff,0xffff,0xcb5a,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2421,0xd7bd,0xffff,0xffff,0xffff,0xffff,0xf7bd,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x6108,0x8631,0x4d6b,0xb6b5,0xffff,0xffff,0xffff,0xffff,0xffff,0x3ce7,0xe318,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x38c6,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x5def,0x8631,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x55ad,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x9ad6,0x2421,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x718c,0xffff,0xffff,0xffff,0xffff,0x7def,0xcf7b,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x8e73,0x5def,0x79ce,0xf39c,0xaa52,0x4108,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 }; //glyph_0_data

glyph_t glyph_0 = {
.width = 17,
.length = 782,
.data = glyph_0_data
};


// 'A' character
const uint16_t glyph_1_data[] = {
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xeb5a,0xffff,0xffff,0xffff,0xffff,0x3084,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xb6b5,0xffff,0xffff,0xffff,0xffff,0xdbde,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8210,0xdfff,0xffff,0xffff,0xffff,0xffff,0xffff,0x6529,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xeb5a,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x1084,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x96b5,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xbad6,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4108,0xbef7,0xffff,0xffff,0x79ce,0x9ad6,0xffff,0xffff,0xffff,0x2421,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xaa52,0xffff,0xffff,0xffff,0x1084,0x1084,0xffff,0xffff,0xffff,0xae73,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x14a5,0xffff,0xffff,0xffff,0x8631,0x8631,0xffff,0xffff,0xffff,0x18c6,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7def,0xffff,0xffff,0x1ce7,0x0000,0x0000,0x1ce7,0xffff,0xffff,0xffff,0x8210,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xc739,0xffff,0xffff,0xffff,0xb294,0x0000,0x0000,0xd39c,0xffff,0xffff,0xffff,0xcb5a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3084,0xffff,0xffff,0xffff,0x694a,0x0000,0x0000,0x8a52,0xffff,0xffff,0xffff,0x34a5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x79ce,0xffff,0xffff,0xdfff,0x6108,0x0000,0x0000,0x6108,0xdfff,0xffff,0xffff,0x7def,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0xa210,0xffff,0xffff,0xffff,0xf7bd,0x0000,0x0000,0x0000,0x0000,0x18c6,0xffff,0xffff,0xffff,0xa631,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0xeb5a,0xffff,0xffff,0xffff,0xcf7b,0x0000,0x0000,0x0000,0x0000,0x1084,0xffff,0xffff,0xffff,0xef7b,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x14a5,0xffff,0xffff,0xffff,0xc739,0x0000,0x0000,0x0000,0x0000,0x0842,0xffff,0xffff,0xffff,0x18c6,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x3ce7,0xffff,0xffff,0x9ef7,0x2000,0x0000,0x0000,0x0000,0x0000,0x4108,0xdfff,0xffff,0xffff,0xdfff,0x6108,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x4529,0xffff,0xffff,0xffff,0xb6b5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x18c6,0xffff,0xffff,0xffff,0x494a,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x6d6b,0xffff,0xffff,0xffff,0xae73,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1084,0xffff,0xffff,0xffff,0x718c,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x96b5,0xffff,0xffff,0xffff,0xa631,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0842,0xffff,0xffff,0xffff,0x9ad6,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x9ef7,0xffff,0xffff,0x9ef7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4108,0xdfff,0xffff,0xffff,0xffff,0x8210,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x8631,0xffff,0xffff,0xffff,0xb6b5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x18c6,0xffff,0xffff,0xffff,0x8a52,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x8e73,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x9294,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x96b5,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x79ce,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x7def,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x6108,0x0000,0x0000,
0x0000,0x0000,0x6529,0xffff,0xffff,0xffff,0x55ad,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x75ad,0xffff,0xffff,0xffff,0x494a,0x0000,0x0000,
0x0000,0x0000,0x4d6b,0xffff,0xffff,0xffff,0xcf7b,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xef7b,0xffff,0xffff,0xffff,0x3084,0x0000,0x0000,
0x0000,0x0000,0x34a5,0xffff,0xffff,0xffff,0x494a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x694a,0xffff,0xffff,0xffff,0xf7bd,0x0000,0x0000,
0x0000,0x0000,0xfbde,0xffff,0xffff,0xffff,0xa210,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xe318,0xffff,0xffff,0xffff,0xbef7,0x2000,0x0000,
0x0000,0xc318,0xffff,0xffff,0xffff,0x3ce7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7def,0xffff,0xffff,0xffff,0xa631,0x0000,
0x0000,0x694a,0xffff,0xffff,0xffff,0xd7bd,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x18c6,0xffff,0xffff,0xffff,0x6d6b,0x0000,
0x0000,0x3084,0xffff,0xffff,0xffff,0x718c,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xb294,0xffff,0xffff,0xffff,0x34a5,0x0000,
0x0000,0xd7bd,0xffff,0xffff,0xffff,0x2c63,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4d6b,0xffff,0xffff,0xffff,0xfbde,0x0000,
0x0000,0x7def,0xffff,0xffff,0xffff,0xc739,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xc739,0xffff,0xffff,0xffff,0xffff,0xa210,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
}; //glyph_1_data

glyph_t glyph_1 = {
.width = 24,
.length = 1104,
.data = glyph_1_data
};

font_t font = {
.height = 48,
.glyphs[] = {glyph_0, glyph_1}
};

int main()
{
printf("\n");
printf("%d\n", font.height);
printf("%d\n", font.glyph[0].width);
printf("%d\n",font.glyph[0].data[106]);
printf("%d\n", font.glyph[1].width);
printf("%d\n",font.glyph[1].data[106]);
}

编译时出现如下错误:

font2.c:133:2: error: array index in initializer exceeds array bounds
.glyphs[2] = {glyph_0, glyph_1}
^
font2.c:133:2: error: (near initialization for ‘font.glyphs’)
font2.c:133:2: error: initializer element is not constant
font2.c:133:2: error: (near initialization for ‘font.glyphs[0].width’)
font2.c:133:2: error: initializer element is not constant
font2.c:133:2: error: (near initialization for ‘font.glyphs[0].length’)

我也试过:

font_t font;
font.height = 48;
font.glyphs[0] = glyph_0;
font.glyphs[1] = glyph_1;

编译时出现以下错误:

 gcc -o test font2.c 
font2.c:132:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
font.height = 48;
^
font2.c:133:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
font.glyphs[0] = glyph_0;
^
font2.c:134:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
font.glyphs[1] = glyph_1;

我还尝试了 "glyphs[2]""glyphs[]" 的各种组合,但没有成功。我不知道这两个错误是什么意思。任何帮助将不胜感激。

最佳答案

您的另一个答案解释了您的方法中的语法和语义问题;请不要接受这个。我只想补充一点,您可以在文件范围内执行初始化,只要您愿意使用文字。这对我来说似乎是合理的,因为我不明白为什么要像原始代码尝试那样复制字形数据。它可能看起来像这样:

font_t font = {
.height = 48,
.glyphs = {
{ .width = 17, .length = 782, .data = glyph_0_data },
{ .width = 24, .length = 1104, .data = glyph_1_data }
}
};

关于c - 将结构数组嵌套到另一个结构中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45244561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com