【问题标题】:Unexpected Error at #include Statement#include 语句出现意外错误
【发布时间】:2015-07-21 08:25:41
【问题描述】:

问题

当我#include <arpa/inet.h> Xcode 在#include 语句处生成错误Expected identifier or '(' 错误时,我正在尝试在BSD 套接字上实现网络接口。


代码

snc_network.h

#ifndef __lib_Syncrology__snc_network__
#define __lib_Syncrology__snc_network__

#include "snc_def.h"
#include <arpa/inet.h>//Error Here:Expected identifier or '('
//Type Definations

typedef union
{
   struct sockaddr_in6 in6_addr;
   struct sockaddr_in in_addr;
   struct sockaddr addr;
}snc_sockaddr_t;

#endif /* defined(__lib_Syncrology__snc_network__) */

snc_def.h

//Preprocessor Definations
#define __SYNCROLOGY_VERSION_NUMBER__ 0.0.1;



//Type Definitions



//Padding
typedef unsigned char snc_pad_t;

//Private;
typedef void snc_prv_t;

//snc Data Sturcture
typedef struct
{
    uint16_t sncprot_id;
    uint16_t sncprot_ref; //Refence Count
}snc_struct;

//Application Data
typedef struct
{
   void *data;
   size_t data_size;
}snc_appdata_t;

//Functions

//Null
bool snc_null(snc_struct *sncstruct);

//Reference Count
bool snc_retain(snc_struct *sncstruct);
void snc_release(snc_struct *sncstruct);

提前致谢。

【问题讨论】:

  • #define 上的 0.0.1 是什么 SYNCROLOGY_VERSION_NUMBER 0.0.1;那也有一个错误的分号?

标签: c xcode xcode6 c-preprocessor


【解决方案1】:

几乎可以肯定是因为行中有错误的分号

#define __SYNCROLOGY_VERSION_NUMBER__ 0.0.1;

并且,永远不要使用以下划线开头的宏。这是 C 语言中未定义的行为。修复那个宏,以及你的包含保护。

并且,如果您针对 POSIX,永远不要_t 结束变量:它们也是保留的。

【讨论】:

    【解决方案2】:

    这个定义

    #define __SYNCROLOGY_VERSION_NUMBER__ 0.0.1;
    

    错了,

    首先它不能有分号。其次,没有像0.0.1这样的pp-token

    【讨论】:

    • 我google了,但还是不知道pp-token是什么意思。你能解释一下吗?谢谢。
    【解决方案3】:

    即使“#define SYNCROLOGY_VERSION_NUMBER 0.0.1;”行的分号是不必要的,它也不应该给出编译错误,对吧?

    尝试在 snc_def.h 之前定义 inet.h ... :)

    #include <arpa/inet.h>
    #include "snc_def.h"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多