在迁移到C ++时,我需要一个似乎已被弃用的特定函数。
sorry, unimplemented: non-trivial designated initializers not supported
在内存约束系统中,用C ++实现以下数据存储系统的正确方法是什么?
typedef union union_t {
float f;
int i;
} arg;
typedef struct type_t {
int a;
arg b;
int d;
} element;
const element list[] = {
{
.a = 1,
.b = { .f = 3.141519f },
.d = 6
},
{
.a = 3,
.b = { .i = 1 },
}
};
通常建议使用std:map
或std:vector
。哪一个合适,但是list
是不变的,必须能够编译并链接到特定的Flash块。两者似乎都不适合该目的。
我能走的最高的是ARM编译器6,它是C ++ 14。
您显示的方式几乎完全符合传入的C ++ 20标准。只有那.d
也必须初始化。是我建议使用的。
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0329r4.pdf
要在C ++ 14中处理此问题,您必须将其显式初始化:
typedef union union_t {
float f;
int i;
} arg;
typedef struct type_t {
int a;
arg b;
int d;
} element;
const element list[] = {
{
/*.a = */ 1,
/*.b = */ { /*.f = */ 3.141519f },
/*.d = */ 6
},
{
/* .a = */ 3,
/* .b = */ { /* .i = */ 1 },
0
}
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句