Skip to content

Multiple input files are concatenated, UNLIKE GCC #104

@mrolle45

Description

@mrolle45

PCPP is supposed to be a stand-in for GCC -E. That is, its output can be written to a .i file, which can then be compiled with GCC.
However, if there are two or more input files on the command line, GCC preprocesses them separately and writes all the results consecutively to the output. PCPP concatenates the input files and then preprocesses the concatenated input.
Here's an example.

File a.c:
#define FOO bar
File b.c:
FOO

Output from GCC -E a.c b.c:

# 0 "a.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "a.c"
# 0 "b.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "b.c"
FOO

The define of FOO in a.c is not seen in b.c.

Output from PCPP a.c b.c:

#line 1 "b.c"
bar
  1. Remove (or deprecate) support for multiple input files
    Here, FOO in b.c expands to bar.

In addition, it would be nice for PCPP to mimic the 6 lines of preamble (per input file) from GCC. However, this is not critical, as the output can still be fed to a compiler and produce the same result.

Suggestions

  1. Leave PCPP as-is but document the differences in the output results. Suggest that the user run the inputs separately and then combine the outputs. Print a warning message.
  2. Fix PCPP to conform with GCC. Document this as a breaking change. In pcmd.py, change
            if len(self.args.inputs) == 1:
                self.parse(self.args.inputs[0])
            else:
                input = ''
                for i in self.args.inputs:
                    input += '#include "' + i.name + '"\n'
                self.parse(input)

to

              for i in self.args.inputs:
                self.parse(input)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions