zoukankan      html  css  js  c++  java
  • incomplete type is not allowed

    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];
    };

    编译报错如下:

    ..Usermqtt.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关键字反而没啥问题。

  • 相关阅读:
    Git Merge Request
    Hazelcast Hazelcast介绍与使用
    Git 修改name/author信息
    HDU 2553 N皇后问题(DFS)
    HDU 1070 Milk(水题)
    HDU 2616 Kill the monster(简单DFS)
    HDU 1426 Sudoku Killer(BFS)
    HDU 2216 Game III(BFS)
    URAL 1001 Reverse Root(水题)
    URAL 1902 NeoVenice(水题)
  • 原文地址:https://www.cnblogs.com/htsky/p/5936703.html
Copyright © 2011-2022 走看看