Skip to main content

Reading Compiler Output

beginner14 min readLesson 68 of 148

Warnings are the compiler handing you the bug report before the crash.

Compile with warnings ON, always

gcc -std=c23 -Wall -Wextra -o app main.c

-Wall -Wextra is the default posture for this course's challenges too: the build warnings you see are the same ones the grader sees.

The warnings that mark real bugs

  • unused variable โ€” you computed something and never used it: often a forgotten step
  • uninitialized โ€” the value is read before any assignment: undefined behavior waiting to happen
  • wrong format specifier โ€” printf("%d", 3.14) prints garbage: the type and the format must agree
  • control reaches end of non-void function โ€” a code path returns nothing
  • assignment in condition โ€” if (x = 5) assigns, then tests 5; you probably meant ==

Read errors bottom-up

The FIRST error is the real one; later errors are often its shockwaves. Fix the first, recompile, repeat. And read the caret line (^) โ€” the compiler points at the exact token it choked on.

Error vs warning

A warning compiles anyway โ€” the program runs, wrongly. The discipline: treat every warning as a bug. -Werror (turn warnings into errors) is how professional builds enforce it.

Now practice

Warning ForensicsFix the classic warning-marked defects: assignment-in-condition, wrong format, missing return, uninitialized read.4 challenges ยท ยท ~16 min