Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 预期标识符或‘;(’;在数字常量之前?_C_Linux - Fatal编程技术网

C 预期标识符或‘;(’;在数字常量之前?

C 预期标识符或‘;(’;在数字常量之前?,c,linux,C,Linux,我有这个头文件…出于某种原因,我一直得到一个错误,说 log_server.h:48:错误:预期标识符或数字常量前的“(” 我在定义put_evt和print_evt_list函数的两行中都遇到了这个错误, 下面是代码的样子: #ifndef _GENERIC #define _GENERIC #include <string.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #

我有这个头文件…出于某种原因,我一直得到一个错误,说
log_server.h:48:错误:预期标识符或数字常量前的“(”
我在定义put_evt和print_evt_list函数的两行中都遇到了这个错误, 下面是代码的样子:

#ifndef _GENERIC
#define _GENERIC
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif

#ifndef _NETWORKING
#define _NETWORKING
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
typedef struct sockaddr SA;/* To make casting in the (bind, recvfrom, sendto) more readable */
#endif

#define LOGIN_EVT 0
#define LOGOUT_EVT 1

#define RECV_MSG 27
#define SEND_MSG 64000
#define MAX_EVT_COUNT 3000

struct evt{ 
    char user_name[8];
    int type;
    long int time;
};



/* open log file to append the events to its end
 * return 0 on success and -1 on failure (file could not be opened)
 */
int init_log(const char *log_fname);

/* closes the log file
 * return 0 on success and -1 on failure (file could not be opened)
 */
int terminate_log();

/* add new event to the log file
 * return 0 on success and -1 on failure
 */
int put_evt(struct evt *e);

/* get list of events that occured after the given time
 * count is the size of the allocated and passed e-list
 * return number of found events on success and -1 on failure
 */
int get_events(struct evt  *e_list, long int time);

/* print given event's info (name, time)*/
void print_evt(struct evt  *e);

/* print "count" event's info from the given e_list info (name, time)*/
void print_evt_list(struct evt  *e_list, int count);

/* startListen takes a port number and returns a listening descriptor on sucess or negavtive on error  */
int startListen(int port);

/* Responsbile for hanlding received messages from clients and responding to them accordingly
if the message is an action done, it'll save it in the log file and notify the client
if the message is a query about the events, it'll call the private function queryHandler(); to handle it
returns negative on ERROR*/
int handle_message(int sockDescriptor, struct sockaddr_in *client, char *recvMessage);
\ifndef\u通用
#定义泛型
#包括
#包括
#包括
#包括
#包括
#恩迪夫
#ifndef\u网络
#定义网络
#包括
#包括
#包括
#包括
#包括
typedef struct sockaddr SA;/*使(bind、recvfrom、sendto)中的强制转换更具可读性*/
#恩迪夫
#定义登录\u EVT 0
#定义注销\u EVT 1
#定义RECV_MSG 27
#定义发送消息64000
#定义最大EVT计数3000
结构evt{
字符用户名[8];
int型;
时间长;
};
/*打开日志文件以将事件附加到其末尾
*成功时返回0,失败时返回-1(无法打开文件)
*/
int init_log(const char*log_fname);
/*关闭日志文件
*成功时返回0,失败时返回-1(无法打开文件)
*/
int terminate_log();
/*将新事件添加到日志文件
*成功时返回0,失败时返回-1
*/
int put_evt(结构evt*e);
/*获取给定时间后发生的事件列表
*count是已分配和已传递的电子列表的大小
*成功时返回找到的事件数,失败时返回-1
*/
int get_事件(结构evt*e_列表,长int时间);
/*打印给定事件的信息(名称、时间)*/
无效打印(结构evt*e);
/*从给定的e_列表信息(名称、时间)打印“计数”事件的信息*/
无效打印evt列表(结构evt*e列表,整数计数);
/*startListen获取端口号,并在成功时返回侦听描述符,在出错时返回Negative*/
int startListen(int端口);
/*hanlding的Responsible从客户端接收消息并相应地对其进行响应
如果消息是已完成的操作,它将保存在日志文件中并通知客户端
如果消息是关于事件的查询,它将调用私有函数queryHandler();来处理它
错误时返回负数*/
int handle_消息(int sockDescriptor,struct sockaddr_in*client,char*recvMessage);
我已经读到,这个错误可能是由在多行上写入预处理指令引起的……但我不知道。知道我做错了什么吗?

我想您已经在前面的标题中定义了e 2.71828183或类似的内容


为了确定答案,请通过预处理器运行代码并查看输出。在gcc中,这是-E命令行开关,我会尝试稍微重命名函数。有时,如果其中一个头正在定义令牌(例如“put_evt”)如果您使用,预处理器将损坏您的代码。

问题是我在另一个位置声明了
struct evt

我遇到了完全相同的问题,并且发现
struct evt
是在另一个位置定义的。

可以方便地指出第48行,以排除某种奇怪的宏/杂项关于预处理奇怪之处,您应该检查预处理的输出,看看它是否正常。使用
gcc
可以使用
-E
标志来完成这项工作。我已经说过,在函数put\u evt和print\u evt上都给出了错误_list@Someone:已多次建议使用
-E
选项,但让我们再试一次:wh命令
gcc-esourcefile.c|grep put_evt
会说什么?(调整您可能需要为
gcc
添加的任何选项,例如
-I
)。它是这么说的……但实际上并不意味着任何有意义的东西:
int put_evt(struct evt*E);int put_evt(struct evt*E)
@MichaelBurrIts不是函数…而是函数附近的
)后面的东西。解决方案是…?@Someone:重命名原型以使用不同的参数名称:
void print\u evt(struct evt*ev)
完全从原型中删除参数的名称,因为它绝对不必要。@有人认为问题一定是其他问题。使用-E选项!当我使用与结构同名的makefile定义时,我遇到了相同的问题。我在键入错误代码枚举时遇到了相同的问题,而错误代码枚举恰好具有相同的ident库中的定义覆盖另一个库中的定义时,我遇到了相同的问题,尽管报告错误的定义不是被覆盖的定义。相反,它在被覆盖的定义中使用的定义上报告了错误。最简单的解决方案是在主库包括,因此它可以保持相同的名称而不受干扰。