This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compilation Error: declaration may not appear after executable statement in block

Hi,

I have a compilation error I cant solve.

The error is:
\video\milgem_video_processing_functions.c", line 332: error: declaration may not appear after executable statement in block
\video\milgem_video_processing_functions.c", line 333: error: expected a ";"

The code chunk is:

unsigned short draw_icon(Video_Frame *video_frame, Uint8 icon_name, Uint32 icon_coo_x, Uint32 icon_coo_y) //line 332
{                                                                                                                                                          //line 333
 Uint32 line_no;
 Uint32 pixel_no;
 ...

 ...

 ...

}

 

As seen, there is no syntax error at the related lines.(and any above lines) Does anyone meet such an compilatio error before?

Thanks in advance.

  • I believe this error occurs when you have your variable declarations after executable statements; normally, moving variables to variable declaration blovk fix this.  Looking at your source code, I imagine that the previous function may not have been terminated correctly (e.g. missing "}") and hence the compiler is thinking that your function declaration is actually a variable declaration. 

    Also, do you have the function prototype definition for this function somewhere before the implementation of this function?  it may be another potential reason.

  • I dont have any variable declaration after any executable statement block. Also I don't have any missing curly braces in the above function. I did have the prototype definition of the function, but I erased it. The problem continues. Thats one of the most annoying things I am up to.

     

  • Well that matter is solved, the reason was two match cury braces were in the same direction.

    But now I am battling another silly problem.

    There are three errors:

    line 35: error: expected a "}"

    line 35: error: expected a "}"

    line 35: error: expected a decleration

     

    The expected curly braces are totally unnecessary and will be wrong if I put them because;

    const struct coordinate_table_s coordinate_table[] =
    {
        {
            CONN_1_TEXT_AREA_POS_X,
            CONN_1_TEXT_AREA_POS_Y,  //LINE 35
            CONN_1_ICON_1_POS_X,
            CONN_1_ICON_1_POS_Y,
            CONN_1_ICON_2_POS_X,
            CONN_1_ICON_2_POS_Y,
            CONN_1_ICON_3_POS_X,
            CONN_1_ICON_3_POS_Y
        },

        ...

        ...

        ...

    };

     

    There is no mismatch curly braces prior to this constant table. You may consider this table is the first thing in the .c file if you dont count the include definitions.

     

     

     

  • I cannot readily see anything wrong with the code segment above; are the CONN_1_XXX_XXX_XXX_XXX values set as "#defines"?  can you also post the definition of the "coordinate_table_s" data structure?