Parse errors
balzano_1_at_yahoo.com
Date: 06/28/05
- Previous message: Joe Beanfish: "Re: Disk I/O stats from /proc/diskstats"
- Next in thread: Eric Taylor: "Re: Parse errors"
- Reply: Eric Taylor: "Re: Parse errors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Jun 2005 10:24:39 -0700
The code below is fairly straight forward; it copies one structure to
another and sends it to a server on port 7000, the additional header
file that is "info.h" compiles fine and is only used to provide the
structure that is to be copied. (If info.h is needed I'll be happy to
post it)
#include "stdio.h"
#include "unistd.h"
#include "stdlib.h"
#include "string.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "netdb.h"
#include "arpa/inet.h"
#include "ctype.h"
#include "info.h" /*Header the provides the run() function see for(;;)
*/
#define SIZE sizeof(struct sockaddr_in);
struct sockaddr_in server;
int main(void){
int sockfd;
info *inf = NULL;
memset(&server, 0, sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_port = 7000;
inf = (info *)malloc(sizeof(info));
if(inf == 0){
perror("malloc() :");
exit(EXIT_FAILURE); }
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket() failed!");
exit(EXIT_FAILURE);
}
if(connect(sockfd, (struct sockaddr *) &server, SIZE) == -1)
{
perror("connect() failed");
exit(EXIT_FAILURE);
}
for(;;){
write(1, "gathering", 10);
*inf = run(); /*copies a returned structer to the inf
structure*/
send(sockfd, inf, sizeof(inf), 0);
write(1, "sent", 4);
}
close(sockfd);
return 0;
}
When compiled using a recent version of gcc (4.0.0 or 3.4.4) it
compiles fine, if however it's compiled using gcc 2.95.3 I get the
following errors:
client.c: In function `main':
client.c:44: parse error before `;'
client.c: At top level:
client.c:51: parse error before `for'
client.c:53: warning: type defaults to `int' in declaration of `inf'
client.c:53: incompatible types in initialization
client.c:53: initializer element is not constant
client.c:53: warning: data definition has no type or storage class
client.c:54: parse error before `sizeof'
client.c:54: warning: type defaults to `int' in declaration of `send'
client.c:55: parse error before `1'
client.c:55: warning: type defaults to `int' in declaration of `write'
client.c:55: warning: data definition has no type or storage class
client.c:57: warning: type defaults to `int' in declaration of `close'
client.c:57: warning: parameter names (without types) in function
declaration
client.c:57: warning: data definition has no type or storage class
client.c:58: parse error before `return'
Apart from the unused header files, what am I doing wrong? Any
suggestions will be much appreciated
Thank you,
- Previous message: Joe Beanfish: "Re: Disk I/O stats from /proc/diskstats"
- Next in thread: Eric Taylor: "Re: Parse errors"
- Reply: Eric Taylor: "Re: Parse errors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|