Search notes:

gcc -P

gcc -P prevents the preprocessor from including line markers in its output.

main.c

Here's a simple c program that includes a header file (foo.h):
#include "foo.h"

int main() {}
Github repository about-gcc, path: /options/P/main.c

foo.h

The included foo.h is even more simple:
int foo();
Github repository about-gcc, path: /options/P/foo.h

Makefile

This makefile creates two precompiled versions of main.c, one using the -P option and one without it:
all: main_p.i main.i

main.o: main.i
	gcc -c $< -o $@

main_p.i: main.c foo.h
	gcc -E -P $< -o $@

main.i: main.c foo.h
	gcc -E $< -o $@
Github repository about-gcc, path: /options/P/Makefile

main.i

main.i is the file that was created without the -P option. Thus, it contains line markers in it:
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "main.c"
# 1 "foo.h" 1
int foo();
# 2 "main.c" 2

int main() {}
Github repository about-gcc, path: /options/P/main.i

main_p.i

main_p.i was created with the -P option. Thus, it contains no line markers:
int foo();
int main() {}
Github repository about-gcc, path: /options/P/main_p.i

See also

gcc -E
GCC options
The equivalent Visual Compiler options /E, /P and /EP.

Index