Reputation: 1508
I need to debug a C code with lots of macros, of which a bunch of them are not trivial at all and they include several (lots of) lines. That makes it impossible to debug, since macros are expanded in a single line and you never know where an error comes from. On the other hand, its easy with sed
to take the preprocessor output and add lines after each semicolon.
I won't discuss about being a good practice to use macros such as these, because I can't do much about that. But I'd like to know whether I could add an stage to the compiler (I use several compilers:icc,gcc,xlc) between preprocessing and compiling, so it I rund that sed
command.
Upvotes: 1
Views: 131
Reputation: 11831
Define your own "compiler" as a script to run g++ -E
, then your sed
-mangler, then g++
, and specify that one as the compiler overall. Take care to use temporaries courtesy of mktemp
, so starting your compiles in parallel (make -j
) doesn't mess things up.
(Today's GCC doesn't have a separate preprocessing step anymore, so injecting something there can't be done easily anyway.)
Upvotes: 0
Reputation: 1508
By now, I will try with what I found in this post. I also tried the option of the wrapper for compiling single files and, by the moment, it does the trick. In the wrapper, I preprocess (with -E) the file, I then process the preprocessed file with sed
and some rules, and then I compile it.
Upvotes: 0
Reputation: 26194
What you can do is to run the pre-processor only (-E):
$ g++ -E in.c -o in.i
Then run your sed script and compile it's output with g++ (no -E this time). You could construct a rule for doing all this in your Makefile, I'm sure.
Upvotes: 3