0
我在Arduino的C上工作。我试图初始化一个结构(链表)内的指针。它是一个数据对象,所以我想一次初始化整个对象,而不是稍后在代码中使用malloc。C - 初始化结构中的指针
const int PINS_LEN = 20;
struct Command {
float toBrightness; //Percent
float overTime; //Seconds
};
struct CommandNode {
struct Command command;
struct CommandNode *next;
};
struct Sequence {
struct CommandNode commands;
float startTime;
float staggerTime;
int pins[PINS_LEN];
};
struct SequenceNode { //Pattern
struct Sequence sequence;
struct SequenceNode *next;
};
struct SequenceNode pattern = {
.sequence = {
.commands = {
.command = {
.toBrightness = 100,
.overTime = 1.0
},
//-=-=-=THIS IS WHERE IT DIES=-=-=-
.next = {
.command = {
.toBrightness = 50,
.overTime = 0.5
},
.next = NULL
},
//-=-=-=-=-=-=-=-=-=-=
},
.startTime = 0.0,
.staggerTime = 1.0,
.pins = {0, 1, 2, 3, 4, 5}
},
.next = NULL
};
你说的意思是什么“死了” ? – WhiteViking
你不能像这样初始化......你试图初始化一个指针,使其等于一个结构。你可能认为你可以这样做,因为类似的模式适用于C字符串,但它非常专业。您将需要初始化指针以指向具体位置,可能在运行时而不是编译时。 – mah