Skip to content
Tutorials Center
My learning

Topics

C Reference ยท Concepts and Tools

C compilers: gcc, clang and MSVC

Compare the main C compilers (GCC, Clang, MSVC, others), see the command lines to build and warn, detect the compiler in code, and choose a language standard.

A C compiler translates C source into machine code. Behind the single command you type there are usually four steps: the preprocessor expands macros and includes, the compiler proper turns C into assembly, the assembler produces an object file, and the linker combines object files and libraries into an executable. Most compiler drivers (gcc, clang, cl) run all four.

The language is defined by the ISO standard, but compilers differ in the extensions they add, the warnings they give, the standard library they pair with, and how much of newer standards (C23) they support. Knowing the main ones and their flags helps you build the same program on every platform.

The main compilers

Compiler Command Typical platform Notes
GCC (GNU Compiler Collection) gcc Linux, BSD, Windows (MinGW, MSYS2), embedded The long-time default on Linux; very wide target support. This site's runner uses GCC 15.2.
Clang (LLVM) clang macOS (Apple Clang), Linux, Windows, Android Clear diagnostics, shares sanitizers, tooling (clang-tidy, clang-format) and library support. Command-line compatible with GCC.
MSVC cl Windows (Visual Studio) Microsoft's compiler; modern versions support C11 and C17, with C23 support still partial. Different flag syntax (/W4, /std:c17).
Clang-cl clang-cl Windows Clang with MSVC-style flags.
Intel oneAPI (icx) icx x86 servers LLVM-based; strong vectorization.
TinyCC tcc quick scripts Very fast to compile, little optimization.
Embedded vendors IAR, Keil ARMCC, arm-none-eabi-gcc, SDCC microcontrollers Often add their own extensions and limits.

Common command lines

Read-only; run these in your own shell.

TEXT
# GCC / Clang: compile and link in one step, current standard, many warnings
gcc   -std=c23 -Wall -Wextra -Wpedantic -O2 main.c -o main
clang -std=c23 -Wall -Wextra -Wpedantic -O2 main.c -o main

# Separate steps (what the driver does for you)
gcc -E main.c -o main.i        # preprocess only
gcc -S main.c -o main.s        # compile to assembly
gcc -c main.c -o main.o        # compile to an object file
gcc main.o util.o -o main      # link

# MSVC (Developer Command Prompt)
cl /std:c17 /W4 /O2 main.c /Fe:main.exe

Older GCC and Clang releases spell the C23 standard -std=c2x. The GNU dialects (-std=gnu23) keep the compiler's extensions; the plain forms (-std=c23) turn off those that conflict with the standard.

Try it

C Ask the compiler who it is

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

C Feature tests instead of version checks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

What matters when choosing and using a compiler

  • Warnings first. -Wall -Wextra catch many mistakes; add -Wpedantic to find non-standard code, -Wconversion and -Wshadow for stricter checks, and -Werror in CI. MSVC: /W4 and /WX.
  • Optimization levels. -O0 (fast build, best for debugging), -O1, -O2 (the usual release level), -O3 (more aggressive, bigger code), -Os (size), -Og (debug-friendly optimization). Optimization can expose undefined behavior that happened to work at -O0.
  • Debug information. -g for the debugger. See Debugging with gdb.
  • Sanitizers (-fsanitize=address,undefined) work in both GCC and Clang. See Sanitizers.
  • Target and architecture. -march=native tunes for your CPU, which makes the binary less portable. Cross compilers use a prefix such as aarch64-linux-gnu-gcc.
  • Extensions. Statement expressions, __attribute__, typeof (before C23), computed goto and __builtin_* functions are GCC and Clang extensions. Use feature macros or attributes to keep portable code portable.
  • Standard library is separate. glibc, musl, the BSD libc and Microsoft's UCRT differ in what they provide; a new compiler on an old library may lack C23 headers, such as <stdbit.h> on older glibc.
  • MSVC differences. No variable-length arrays, historically weak C99 support (much improved), and printf or scanf details that differ for old runtime versions.
  • Compiler Explorer (godbolt.org) lets you compare the assembly of different compilers online.