我想實現我的微控制器(使用AVR-GCC)一個配置讀者與作者,和我遇到了一些編譯錯誤,特別是。造成這種代碼是:的cfg.h
錯誤與聲明結構指針
#include "cfg.h"
struct config_t* config;
config.temp = TEMP_C;
config.precision = 9;
config.time = 0;
config_read(config);
內容:
#ifndef CFG_h
#define CFG_h
#include <avr/eeprom.h>
#include <inttypes.h>
#define TEMP_C 0
#define TEMP_F 1
#define TEMP_K 2
typedef struct config_t {
uint8_t temp;
uint8_t precision;
int32_t time;
} config_t;
void config_read(struct config_t * config);
void config_write(const struct config_t * config);
#endif
和內容cfg.c
:
#include "cfg.h"
void config_read(struct config_t* config) {
eeprom_read_block((void*)&config, (void*)(0), sizeof(config_t));
}
void config_write(const struct config_t* config) {
eeprom_write_block((const void*)&config, (void*)(0), sizeof(config_t));
}
D'oh!原來,我以爲我已經把這個代碼放在主要方法中,但我沒有。儘管如此,它仍然是一個非常神祕的錯 – svbnet
這個問題的所有答案指出了不同的錯誤,但它們都是正確的 – jforberg