error: expected ‘;’ before ‘:’ token

This is a discussion on error: expected ‘;’ before ‘:’ token within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to add a component to an open-source software. I was able to integrate the two successfully ...

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    error: expected ‘;’ before ‘:’ token

    Hi,
    I am trying to add a component to an open-source software. I was able to integrate the two successfully and it was working properly all these days. I am pretty sure that I havent modified the file "peruse.c" which is a part of my component, recently. But, the error is pointing to a line which appears to be normal. Will try to include everything that is relevant, hope someone can give me some suggestions as to what has gone wrong :

    Prototype of the function in question in the peruse.h file.
    Code:
     
    
    int PERUSE_Query_supported_events( int* num_supported,
                                       char*** event_names,
                                       int** events );
    The corresponding peruse.c file which houses the function in question :

    Code:
    typedef struct {
        const char* name;
        const int   id;
    } peruse_event_associations_t;
    
    /**
     * The associations between the peruse event name and id. This array
     * should be ended by the tuple {NULL, PERUSE_CUSTOM_EVENT}.
     */
    static const peruse_event_associations_t PERUSE_events[] = {
        /* Point-to-point request events */
        { "PERUSE_COMM_REQ_ACTIVATE", PERUSE_COMM_REQ_ACTIVATE },
        { ..................................................................................................................................... },
        { NULL , PERUSE_CUSTOM_EVENT}
    };
    
    const int PERUSE_num_events = (sizeof(PERUSE_events) /sizeof(peruse_event_associations_t));
    
    /* Query all implemented events */
    int PERUSE_Query_supported_events( int* num_supported,
                                       char*** event_names,
                                       int** events )
    {
        int i;
        *num_supported = PERUSE_num_events;
        *event_names = (char**) malloc (PERUSE_num_events * sizeof (char *));
        *events = (int*) malloc (PERUSE_num_events * sizeof (int));
    
        for (i = 0; i < PERUSE_num_events; i++) {
            (*event_names)[i] = strdup (PERUSE_events[i].name);
            (*events)[i] = PERUSE_events[i].id;
        }
    
        return PERUSE_SUCCESS;
    }

    The error that I am getting :

    Code:
    peruse.c:60:72: warning: character constant too long for its type
    peruse.c: In function ‘PERUSE_Query_supported_events’:
    peruse.c:60: error: expected ‘;’ before ‘:’ token
    It is pointing to the line :
    Code:
        *event_names = (char**) malloc (PERUSE_num_events * sizeof (char *));
    What could be wrong ?
    Last edited by kris.c; 02-10-2008 at 10:36 AM.
    In the middle of difficulty, lies opportunity

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    after removing the errors due to me not having some constants in your code declared, and the line in peruse_event_associations_t
    Code:
    {...................}
    which is supposed to be what, by the way--it compiles with no errors.

    i dont see any syntax errors in the given code either. can you verify the code your compiling and posting are the same? sorry no other ideas!

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you really have that big long line of periods in there? That seems like the most likely place to have a character constant too long for its type, although where the ':' comes from I don't know.

    My Hat of Guessing is feeling desperate, but gives the advice of asking you to check some macro definitions, as I guess something has to expand into that colon (since I don't see one). There should be a flag for your compiler to tell it to only pre-process and not compile so you can see the (probably pretty ugly) processed output. Maybe that will help; probably not, but it's the best I can see.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    You probably are missing a " character somewhere, or have an extra one.

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Thanks a lot for the pre-processor hint, I used the -E flag and it indicated what was going wrong. Turns out, I had to use a wrapper defined by the open-source software for malloc, strdup and calloc functions.I find it surprising that it worked over the last two weeks.
    Thanks again
    In the middle of difficulty, lies opportunity

  6. #6
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    By the way, the long set of periods, I should have explained. I put that in to indicate that there are many more such lines.
    In the middle of difficulty, lies opportunity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-26-2008, 04:43 AM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Parsing and Tokens (strtok)
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 04-22-2002, 09:57 AM

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