【发布时间】:2020-04-21 12:21:28
【问题描述】:
在关于 SO 和其他地方的类似问题中,在这种情况下讨论的唯一解决方案是使用数组表示法初始化结构数组,而不是使用结构成员的点名。我最接近我想要的是使用以下代码:
int texturesCount = 2;
struct textureParams textures[texturesCount];
struct textureParams textures0 = {
.textureFormat = textureFormat,
.textureAccess = textureAccess,
.srcrect = {.x = 0, .y = 0, .w = 50, .h = 50},
.dstrect = {.x = 0, .y = 500, .w = 50, .h = 50},
.r = 255,
.g = 0,
.b = 0,
.a = 0,
};
struct textureParams textures1 = {
.textureFormat = textureFormat,
.textureAccess = textureAccess,
.srcrect = {.x = 0, .y = 0, .w = 20, .h = 20},
.dstrect = {.x = 10, .y = 100, .w = 20, .h = 20},
.r = 0,
.g = 255,
.b = 0,
.a = 0,
};
textures[0] = textures0;
textures[1] = textures1;
有没有办法做到这一点 - 参考命名的结构成员创建数组的结构成员 - 但不创建临时变量 texture0 和 texture1?
【问题讨论】:
标签: c arrays struct initialization variable-assignment