Parse errors

balzano_1_at_yahoo.com
Date: 06/28/05

  • Next message: Eric Taylor: "Re: Parse errors"
    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,


  • Next message: Eric Taylor: "Re: Parse errors"

    Relevant Pages

    • Help with makeing DBD::DB2
      ... Constants.xs:25: warning: `not_here' defined but not used ... dbdimp.h:18: error: parse error before '*' token ... dbdimp.h:18: warning: type defaults to `int' in declaration of ...
      (comp.lang.perl.modules)
    • Re: bug in Real-Time Preemption
      ... lib/rwsem.c:153: warning: type defaults to `int' in declaration of `type name' ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: struct enumerating types
      ... The printf() and scanfformat specifiers for all the built-in types ... int main ... t.c:20: warning: no semicolon at end of struct or union ... t.c:43: warning: type defaults to 'int' in declaration of 'printf' ...
      (comp.lang.c)
    • 2.6.13-rt14 build problem on Powerpc board
      ... kernel/ntp.c:84: warning: excess elements in scalar initializer ... kernel/ntp.c:104: warning: type defaults to `int' in declaration of ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: anything wrong with this?
      ... foo.c:1: parse error before `if' ... foo.c:6: warning: type defaults to `int' in declaration of `strcpy' ...
      (comp.lang.c)