我在以下種類的佈局中有一些代碼,我相信當我撥打addTopBotExample
時topExample
/botExample
未被正確設置。我認爲這是由於頂級bot變量位於函數堆棧中,並在函數結束時被清除?我有一種感覺,也許我需要首先記憶,但我不知道如何去做這件事,即使它是正確的方法。設置結構體變量 - C
typedef struct Example Example;
struct Example {
/* normal variables ...*/
Example *topExample;
Example *botExample;
};
....
void addTopBotExample(Example **example, int someVariable) {
Example top = createTopExample(int someVariable); //(createTopExample returns a
//type Example based on some input)
Example bot = createBotExample(int someVariable);
(*example)->topExample = ⊤
(*example)->botExample = ⊥
return;
}
由於這確實是這個問題。 – 2013-02-08 23:54:18