Skip to content

/errors/c/expected-semicolon-before

gcc error: expected ';' before

The commands on this page have not been executed by our verification runner yet.updated
tool
C
exit code
1
versions
GCC 4+, Clang (different wording)
os
linux, macos, windows

error: expected ';' before 'X' means GCC reached token X while the previous statement was still open: a semicolon is missing just before it. The compiler only notices at the next token, so look at the end of the statement before X, which is often on the previous line. Add the semicolon there, or after the } of a struct or enum definition. Clang reports the same problem as error: expected ';' after expression.

Example

main.c
#include <stdio.h>

int main(void) {
    int total = 0
    printf("%d\n", total);
    return 0;
}

GCC reports error: expected ';' before 'printf': it names the token it did not expect. Depending on the GCC version, the location shown is either the end of line 4 (with a fix-it hint that shows the missing ;) or the start of printf on line 5. Either way the fix is a ; after int total = 0.

Checklist

WhereWhat is usually missing
End of the previous lineThe semicolon of a declaration, assignment or function call
After a closing bracestruct, union, enum or typedef definitions need };
do { ... } while (cond)The ; after while (cond)
Inside a headerA prototype or declaration without ; (the error appears in the .c file after the #include)
A type name before the tokenA missing #include, so the type is unknown and parsing goes wrong

Sources