The Compile–Link–Load Toolchain

a compiler warning versus an error

When you build a program, the compiler talks back to you with diagnostics, and they come in two strengths. An error means the compiler cannot proceed: the code violates a rule of the language, so no output is produced and you must fix it before anything will build. A warning means the code is legal enough to compile, the compiler will produce output, but it has spotted something that looks suspicious or likely wrong and is choosing to tell you rather than stop. An error is a locked door; a warning is a yellow caution sign you are free, but unwise, to drive past.

Concretely, a missing semicolon, an undeclared variable, or a type that cannot possibly work is an error, and the build halts. By contrast, comparing a signed and an unsigned number, using a variable before it is initialised, or writing if (x = 5) when you probably meant == are warnings: each compiles to a working binary, yet each is a classic source of real bugs. Compilers stay quiet about many of these by default, which is why experienced programmers turn warnings up with flags like -Wall and -Wextra, and often add -Werror to promote warnings into errors so the build refuses to finish until they are addressed.

The dangerous misconception to retire is that 'it compiled with no errors' means 'my program is correct'. It does not. A clean compile only certifies that the code obeys the language's grammar and basic type rules; it says nothing about whether the logic is right, and it certainly does not catch undefined behavior, which compiles silently and may corrupt or crash only later. Warnings are the compiler doing its best to flag likely mistakes for free, so treating them as noise to be ignored throws away one of the cheapest and most effective bug-finding tools you have.

$ gcc -Wall main.c -o app main.c:4: warning: suggest parentheses around assignment used as truth value if (x = 5) { ... } // compiles & runs, but you probably meant x == 5 # -Werror would turn this warning into an error and stop the build

A warning still builds a runnable program, but flags a line that is very likely a bug.

'No errors' only means the code is grammatically legal, not that it is correct; warnings often point straight at real bugs, and undefined behavior can compile with neither a warning nor an error.

Also called
warnings vs errorsdiagnostics警告與錯誤