Ben yapılar (genellikle) nasıl başlatıldığını biliyorum ama bir yapı malzeme içindeStruct başlatma hatası
typedef struct Location{
uint8_t x;
uint8_t y;
} loc;
typedef struct Person{
loc location;
} person;
küresel değişkenleri bu yapı ile sorun yaşıyorum:
static person hero;
başlatma işlevlerini:
void InitializeHero() {
person hero = {0,0, {0,0}}; // this compiles
hero.location = {0,0}; // but this does not compile
hero = {0,0,{0,0}}; // this also does not compile
}
Huh? İlk başlatmanız * derlenmiyor *. '{}' Içinde 4 skaler ve yapıda yalnızca 2 skaler üyeniz var. Bu, C'deki bir hatadır. – AnT
Şunlar için bir veya daha fazla yinelenen: http://stackoverflow.com/q/24138140/694576 – alk
olası bir kopyası [ANSI C'deki bir yapı nasıl başlatılır] (http://stackoverflow.com/questions/330793/nasıl başlatılır-a-struct-in-ansi-c) – alk