Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #552

Re: combining c-code files into one c-code file

From Gene <gene.ressler@gmail.com>
Newsgroups comp.compilers
Subject Re: combining c-code files into one c-code file
Date 2012-04-09 05:40 -0700
Organization Compilers Central
Message-ID <12-04-009@comp.compilers> (permalink)
References <12-04-005@comp.compilers>

Show all headers | View raw


On Apr 3, 9:23 am, Harald Gustafsson <harald.gustafs...@gmail.com>
wrote:
> I'm asking if anyone knows of a tool that can take a list of c-files and
> pre-process/merge that into one c-file, managing redeclarations, conflicting
> declarations, declaration order, etc. The readability of the output is less
> important but prefers as human readable as possible.

I don't know a tool, but I've done this (for a completely different
reason) with a moderately complex program. Conflicting preprocessor
definitions were the main problem as for you. We ended up writing a
script to have gcc dump preprocessor definitions (there is a command
line flag for this), converting them to "undefs".  This was run on
each source file to effectively create a cpp table cleanup that we
could include after each source file.  So the master file looked like

#include "foo.c"
#include "foo.undefs.c"
#include "hoo.c"
#include "hoo.undefs.c"
...

This isn't sufficient for all programs (e.g. the weak symbol case
already mentioned).  E.g. there ware cases where static declarations
conflicted and it was necessary to modify the static name locally with
#define #undef .

...
#define conflicting_static_name BAR_conflicting_static_name
#include "bar.c"
#include "bar.undefs.c"
#undef conflicting_static_name
...

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

combining c-code files into one c-code file Harald Gustafsson <harald.gustafsson@gmail.com> - 2012-04-03 06:23 -0700
  Re: combining c-code files into one c-code file Cameron McInally <cameron.mcinally@nyu.edu> - 2012-04-04 12:02 -0400
  Re: combining c-code files into one c-code file Harald Gustafsson <harald.gustafsson@gmail.com> - 2012-04-04 19:35 +0200
  Re: combining c-code files into one c-code file Gene <gene.ressler@gmail.com> - 2012-04-09 05:40 -0700
  Re: combining c-code files into one c-code file Harald Gustafsson <harald.gustafsson@gmail.com> - 2012-04-18 02:01 -0700

csiph-web