Code compiles on OpenBSD but not on Linux

This is a discussion on Code compiles on OpenBSD but not on Linux within the C Programming forums, part of the General Programming Boards category; I have some code that compiles fine on OpenBSD, but it recieves a parse error when I attempt to compile ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    491

    Code compiles on OpenBSD but not on Linux

    I have some code that compiles fine on OpenBSD, but it recieves a parse error when I attempt to compile it in Linux.
    I am using gcc 2.95.3 on both computers. I am attemping to turn the .c file into an object file with the command:

    Code:
    cc -DDEBUG -DVERSION=\"0.1beta\"  -I./ -g -O3 -Wall -W -pedantic -ansi
     -Wtraditional -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast
     -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return -Wstrict-prototypes
     -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline  -c -o messagequeue.o
     messagequeue.c
    I am getting the errors:

    Code:
    messagequeue.c: In function `messageQueueInit':
    messagequeue.c:20: parse error before `{'
    messagequeue.c:21: parse error before `{'
    Here is the function:
    Code:
    MessageQueue *messageQueueInit ()
    {
      MessageQueue *msgqueue = malloc (sizeof (MessageQueue));
    
      if (msgqueue == NULL)
      {
        /*
           Error here 
         */
        return NULL;
      }
    
      msgqueue->msgcond = PTHREAD_COND_INITIALIZER;
      msgqueue->msgmutex = PTHREAD_MUTEX_INITIALIZER;
    
      pthread_cond_init (&msgqueue->msgcond, NULL);
      pthread_mutex_init (&msgqueue->msgmutex, NULL);
    
      msgqueue->queue = queueInit ();
    
      return msgqueue;
    }
    The oddest part is, lines 20 and 21 are the msgqueue->msgcond = ... lines.

    This code compiles with no trouble in OpenBSD, as of right now I am stumped.

    I obviously didn't put all the code on here since it is rather long, but if anyone wants to see the rest I can put it online.

    Thanks for any tips you can give me.
    Last edited by orbitz; 12-15-2002 at 09:26 PM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Usually these problems come up when there is no new line at the end of the file, but it looks to me like perhaps NULL is defined as somehting other than ((void *)0) or 0. Check and see what NULL is.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Negative, NULL is defined fine. Oddly enough, if I comment this whole function out the rest of the file compiles fine...

    Again, this compiles fine in OpenBSD, and not in Linux.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Thanks for the tip salem, I ran it through the preprocessor and I got this output, However I still cannot see where the problem lies. Maybe I have just been stareing too long.

    Code:
    MessageQueue *messageQueueInit ()
    {
            MessageQueue *msgqueue = malloc (sizeof (MessageQueue));
    
            if (msgqueue == ((void *)0) )
            {
    
    
    
                    return ((void *)0) ;
            }
    
            msgqueue->msgcond = {{ 0, 0  } , 0} ;
            msgqueue->msgmutex = {0, 0, 0, PTHREAD_MUTEX_TIMED_NP, { 0, 0  } } ;
    
            pthread_cond_init (&msgqueue->msgcond, ((void *)0) );
            pthread_mutex_init (&msgqueue->msgmutex, ((void *)0) );
    
            msgqueue->queue = queueInit ();
    
            return msgqueue;
    }

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Well, since I don't actually need those lines I just deleted them and it compiles like it should. I would still really like to know what the problem was if anyone has any ideas.

    Thanks

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Ahh great, thanks alot Salem!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux C source code formatter utility
    By BobS0327 in forum Tech Board
    Replies: 2
    Last Post: 04-08-2006, 07:53 PM
  2. code compiles without error, but
    By kashifk in forum C Programming
    Replies: 9
    Last Post: 04-11-2003, 09:07 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 02:30 PM
  4. Is it harder to code for Linux or Windows?
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-28-2002, 11:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21