Linux 数字常量之前的预期标识符或“(”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10435847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
expected identifier or ‘(’ before numeric constant?
提问by Varda Elentári
I have this header file ... for some reason I keep getting an error saying
log_server.h:48: error: expected identifier or ‘(' before numeric constant
I get this error on both lines defining the put_evt and print_evt_list functions,
here's what the code looks like:
我有这个头文件......出于某种原因,我不断收到错误消息,说
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);
I've read that this error can be caused by having a preprocessing directive written on more than one line ... but I don't have that. Any idea what I'm doing wrong?
我读过这个错误可能是由于在多行上写了一个预处理指令......但我没有。知道我做错了什么吗?
采纳答案by Varda Elentári
the problem was that I had struct evt
declared in another location.
问题是我struct evt
在另一个地方申报了。
回答by Varda Elentári
I think you have #define e 2.71828183
or some such in preceding headers.
我认为您#define e 2.71828183
在前面的标题中有或一些这样的内容。
To find out for sure, run the code through preprocessor and look at the output. In gcc that's -E command line switch
要确定,请通过预处理器运行代码并查看输出。在 gcc 中,这是 -E 命令行开关
回答by Nathan Wiebe
I would try renaming the functions slightly. Sometimes if one of the headers is defining a token (such as "put_evt") that you use, the preprocessor will mangle your code.
我会尝试稍微重命名函数。有时,如果其中一个标头定义了您使用的标记(例如“put_evt”),则预处理器会破坏您的代码。
回答by Killua
I had the exact same problem, and figured out that struct evt
was defined in another location
我遇到了完全相同的问题,并发现它struct evt
是在另一个位置定义的