keil環境下,報錯#70: incomplete type is not allowed,解決
mqtt_conf.h 定義了一個結構體
mqtt_buffer.h
#include <stdint.h>
#include "mqtt.h"
定義了一個結構體
struct MqttBuffer
{
struct MqttExtent *first_ext;
struct MqttExtent *last_ext;
uint32_t available_bytes;
char **allocations;
char *first_available;
uint32_t alloc_count;
uint32_t alloc_max_count;
uint32_t buffered_bytes;
};
c.h
#include <stdint.h>
#include <time.h>
#include "mqtt_conf.h"
#include "mqtt_buffer.h"
定義了一個結構體
struct MqttSampleContext
{
uint32_t sendedbytes;
struct MqttBuffer mqttbuf[1];
struct MqttContext mqttctx[1];
const char *proid;
const char *devid;
const char *apikey;
int dup;
enum MqttQosLevel qos;
int retain;
uint32_t publish_state;
uint16_t pkt_to_ack;
char cmdid[MQTT_LEN_MAX];
};
編譯報錯如下:
..\User\mqtt.h(189): error: #70: incomplete type is not allowed
struct MqttBuffer mqttbuf[1];
搜索了很多文章,沒有找到原因。
后來 受到下面這個鏈接的啟發,原來在mqtt_buffer.h 多了#include "mqtt.h"。原來在a.h里的內容比較少,我將內容搬到mqtt.h里了,所以才加了這句。恢復回去,就好了。
http://zhidao.baidu.com/link?url=HTiXra-5HCPCfj0_VleRYX5s9aDKBLnZjRBOEahUDPMF6u2CYBJ2yuxlaXIZZfihkRl1eWPUJZE-9JAXcmzrZq
結論,#include 的文件之間最好是單向的關系。在功能划分的時候,應盡量避免這個問題。keil的c跟標准的c似乎有些區別,很多時候沒用 extern關鍵字反而沒啥問題。
