Every GCC diagnostic has the same shape:

scratch.c:3:13: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
    3 |   char *s = "scratching surface";
      |             ^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Line 1: file:line:col: severity: message [flag]

  • scratch.c:3:13: where. Columns start at 1. Most terminals/editors make this clickable.
  • severity: error stops the build; warning doesn’t; note: adds context to the diagnostic above it.
  • [-Werror=discarded-qualifiers]: the flag that controls this check. -Werror= means it’s really the warning -Wdiscarded-qualifiers, promoted to an error by -Werror. Search man gcc for /Wdiscarded-qualifiers. -Wno-<name> disables it, which is rarely the right fix.

The message has a fixed vocabulary

The first words say where in the code the problem is:

PhraseMeans
initializationthe = in a declaration (T x = ...)
assignmenta plain x = ...
passing argument N of 'f'a function call
returna return statement

The rest says what’s wrong. Here: “discards ‘const’ qualifier” = a const would be lost (const/volatile are qualifiers); “from pointer target type” = the const is on the thing pointed to, not on the pointer.

Lines 2–3: the source excerpt

^ marks the column, ~~~ underlines the whole expression it’s blaming: here the literal, not s.

note: lines: compare the types

Type errors usually come with a note giving both types:

error: passing argument 2 of 'execv' from incompatible pointer type
note: expected 'char * const*' but argument is of type 'const char * const*'

Put them side by side and read each right to left. The difference is the bug.

The last line: who’s talking

gcc is a driver that runs a pipeline: preprocessor → cc1 (the compiler) → as (assembler) → ld (linker, errors show up via collect2). The prefix tells you which stage complained. undefined reference to 'foo' with no line number = linker: compilation succeeded, the final link couldn’t find foo.

Habits

  • Fix the first error first. One missing ; or } can cause a cascade.
  • Read the note:s.
  • Look the flag up in man gcc before silencing it.