gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Removing comments and expanding macros

#69380 - sgeos - Mon Jan 30, 2006 12:54 pm

Does anyone know and easy way to:
A) remove all comments from a source file
B) expand all macros (mainly interesed in #include)
C) toss the results into another file (easy enough)

NOTE: The files will not necessarily be C source files, although the commenting system and the preprocessor will necessarily be the same.

I'm looking to turn this:
[happy.c]
Code:
/*** happy.c
 *
 * This is a happy module.
 * It makes your sad modules happy!
 */
#include "happy.h"

// This function is happy
void happy(void)
{
   do_print
   (
      "happy"
#if HAPPY_DEBUG
      " debug /* Happy Happy */"
#endif // HAPPY_DEBUG
      "// Really Happy!\n"
   );

   /* FIXME: Cleanup this mess.
    */
   // do_happy_dance(BIG_HAPPY);
   // do_happy_dance(BIG_HAPPY | NOT_SAD);
   do_happy_dance(HAPPY_DEBUG);
}


Into this:
[happy.c.out]
Code:
(whatever happy.h brings in)

void happy(void)
{
   do_print
   (
      "happy"
      "// Really Happy!\n"
   );
   do_happy_dance(0);
}


Or this:
[happy.c.out]
Code:
(whatever happy.h brings in)

void happy(void)
{
   do_print
   (
      "happy"
      " debug /* Happy Happy */"
      "// Really Happy!\n"
   );
   do_happy_dance(1);
}

Depending on how HAPPY_DEBUG is defined.

Well, I'm off to the docs. I vaguely remember reading about a gcc command line option that does all this happy magic. =P

-Brendan

#69396 - tepples - Mon Jan 30, 2006 3:08 pm

Invoking the GCC C Preprocessor
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#69432 - Cearn - Mon Jan 30, 2006 7:30 pm

Also, -E (scroll down a bit). You need to add the output path explicitly, though.

#69544 - sgeos - Tue Jan 31, 2006 12:54 pm

I did saw a magic command line option, I did! (sic) =)
Code:
gcc -E -P file.in -o file.out

Thanks a lot! It does everything I need it to do.

-Brendan

#69662 - Palamon - Wed Feb 01, 2006 12:29 am

Besides bringing all of your code together into one file,
what advantages does this have over having your code spread out over other header files?

Do comments and having portions of your code in other header files increase the compiled file's size? or it's execution speed?

#69672 - sgeos - Wed Feb 01, 2006 2:47 am

Palamon wrote:
Besides bringing all of your code together into one file,
what advantages does this have over having your code spread out over other header files?

I can scan the file to see what tokens are used in it. If the file were C, is there an easier way to do this?

Palamon wrote:
Do comments and having portions of your code in other header files increase the compiled file's size? or it's execution speed?

No.

-Brendan

#69682 - poslundc - Wed Feb 01, 2006 4:58 am

Palamon wrote:
Besides bringing all of your code together into one file,
what advantages does this have over having your code spread out over other header files?


I did some assembly programming a while back that involved some ridiculous amount of macros (the assembly source file was literally 76K - or some 3000 lines of assembly code - before macro expansion), and debugging the syntax errors alone would've been near impossible if I had not been able to invoke the preprocessor independently of the assembler.

Dan.

#69689 - sajiimori - Wed Feb 01, 2006 6:51 am

I've used it to find unreferenced files and remove them from the ROM.