预期的标识符或'('在数字常量之前?

Var*_*ári 8 c linux

我有这个头文件...出于某种原因我一直收到一个错误,说 log_server.h:48: error: expected identifier or ‘(’ before numeric constant 我在定义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);
Run Code Online (Sandbox Code Playgroud)

我已经读过这个错误可能是因为在多行上写了一个预处理指令......但是我没有.知道我做错了什么吗?

Var*_*ári 13

问题是我struct evt在另一个地方宣布过.

  • 当我有一个与结构同名的 makefile 定义时,我遇到了同样的问题。 (2认同)
  • 我在对错误代码枚举进行 typedef 时遇到了同样的问题,该枚举恰好与 [errno](http://www.virtsync.com/c-error-codes-include-errno) 中的标识符具有相同的标识符。 (2认同)

小智 12

我认为你#define e 2.71828183在前面的标题中有或类似的东西.

要确定,请通过预处理器运行代码并查看输出.在gcc中,这是-E命令行切换

  • 完全从原型中删除参数的名称,因为它在那里绝对没有必要。@某人 (2认同)

小智 5

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