2012-05-03 45 views
6

que tienen este archivo de cabecera ... por alguna razón Me aparece un error que dice log_server.h:48: error: expected identifier or ‘(’ before numeric constant consigo este error en las dos líneas que definen el put_evt y funciones print_evt_list, esto es lo que el código se parece a:.identificador esperado o '(' constante antes numérica?

#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); 

he leído que este error puede ser causado por tener una directiva de preprocesamiento escrito en más de una línea ... pero no tengo que alguna idea de qué estoy haciendo el mal?

+3

sería útil para usted para señalar la línea 48 –

+0

cuál es la línea 48? – Naveen

+3

Para descartar algún tipo de rareza de preprocesamiento macro/miscelánea impar, debe comprobar la salida preprocesada y ver si se ve en buen estado. Con 'gcc' esto se puede hacer usando el indicador''E'. – FatalError

Respuesta

12

el problema fue que tuve struct evt declarado en otra ubicación.

+0

Tuve el mismo problema cuando tenía un archivo makefile con el mismo nombre que el de una estructura. – vikasmk

+0

Tuve el mismo problema mientras typedef 'ing un enum de códigos de error que pasó a tener los mismos identificadores que los de [errno] (http://www.virtsync.com/c-error-codes-include-errno). – arnaudoff

12

Creo que tienes #define e 2.71828183 o algo así en los encabezados anteriores.

Para estar seguro, ejecute el código a través del preprocesador y mire la salida. En gcc eso es -E línea de comando cambiar

+0

y la solución para arreglarlo es ...? –

+0

@Someone: Cambie el nombre del prototipo para tomar un nombre de parámetro diferente: 'void print_evt (struct evt * ev);' –

+0

no, el error sigue siendo –

0

Intentaré renombrar las funciones ligeramente. A veces, si uno de los encabezados está definiendo un token (como "put_evt") que utiliza, el preprocesador destruirá su código.

+0

No son las funciones ... es algo justo después del '(' cerca de la función. – abelenky

4

que tenían el mismo problema, y ​​dado cuenta de que struct evt se definió en otra ubicación

Cuestiones relacionadas