1

I preprocessed this test.c to test.i by command gcc -E -o test.i test.c.
test.i has some source file data like # 1 "test.h" 1 in test.i.
Could I have any idea let preprocessor not to generate those strings?

test.i

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "test.c"
# 1 "test.h" 1
int c;
# 1 "test.c" 2

test.c

#include "test.h"

test.h

int c;
eddie kuo
  • 716
  • 1
  • 5
  • 13
  • 2
    On a totally unrelated note: Don't define variables in header files. Such variables will be defines in each [translation unit](https://en.wikipedia.org/wiki/Translation_unit_(programming)) you include the header file in, and when you link them together you will have multiple definition errors. – Some programmer dude Jan 21 '20 at 08:46
  • @Kerndog Yes, this solved my problem. Thank your help. – eddie kuo Jan 21 '20 at 08:52
  • To get back to your original question: I couldn't [find](https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Preprocessor-Options.html) a suitable option. On the other hand, those lines you are interested in to suppress all start with a hash sign (`#`). Wouldn't be difficult to write e. g. a python script to filter these out, just read the fine [line by line](https://stackoverflow.com/a/3277512/1312382) and only print to target file if line doesn't start with a hash... – Aconcagua Jan 21 '20 at 09:13

0 Answers0