Loading lessons...
Common C Errors
Common Compiler Errors
Know the exact messages and you'll fix bugs much faster.
Missing semicolon
expected ';' ...
Forgot at the end of a statement.
Implicit declaration
warning: implicit declaration of function 'print'
Called a function without a prototype/definition. Usually a missing header.
Wrong specifier
printf("%s", 42);
Passing an int where %s expects a string - garbage or crash.
Buffer overflow
char name[5];
strcpy(name, "This is much too long!");
Writing past the array bounds is undefined behavior.
Undefined behavior
- Reading uninitialized variables.
- Using freed pointers.
- Signed integer overflow.
May seem fine, crash later, or behave randomly.
TL;DR
- Read the compiler's message; start at the first error.
- Missing semicolon: add one.
- Wrong header: use the correct one / prototype.
- Watch array sizes to avoid overflow.
- Undefined behavior is a bug even if it works.