Re: Disable printf



Thanks for the reply at first.

I tried the gcc -D "printf(x)=" way. However, it complains about the
printf(x) at the stdio.h, "/usr/include/stdio.h:329:58: macro "printf"
passed 2 arguments, but takes just 1"
I guess the gcc doesn't know how to handle the std c lib if you
redefine printf

I like the idea of putting #include "common.h" line into each c or cpp
files. Do you know how? What kind of script can do this?

Thanks


William Hughes wrote:
RedDevilDan wrote:
I am working on a Memory Footprint Reduction project. I came across an
idea to disable all printf statements so that less memory is required.
In addition, when there is no single printf statement, the printf
library will not be linked, so it further reduces the executable size.
Is there an easy way to disable printf in a large project? In my
project, we have thousands of C & C++ files. They don't have a common
included common header. Otherwise, I can do a #define printf(x) in the
common header. I am using GNU GCC compiler and run the program in both
Linux and VxWorks platform.

Any of you have a suggestion on disabling all printf statements?

I also think about to add a common header file into the whole project.
However, I would need to put a #include "common.h" line into each c
file. It's gonna take a while to do that. Is there any way to insert
the line automatically into each c file?


This is of course about tool sets, not about the C language.

<OT>

Some random ideas.

You might be able to use gcc's -D'name(args..)=definition' option.
Depending on how things are arranged you might be able to
alias gcc or you may have to play around a blit with "PATH" and
the names of binary executables.

You could use your favourite scripting language to
insert the line #include "common.h" at the start of any file
ending ".c" or "cpp". Or you could compile generic.c by compiling
a file containing

#include "common.h"
#include "generic.c"

Again, you should be able to wrap this in a script, call it gcc, change
the PATH variable so that your gcc is called first and link
actual_gcc to /usr/bin/gcc and call actual_gcc from within the srcipt.
Then when the makefiles call gcc, they will get your version

</OT>
- William Hughes

.



Relevant Pages

  • Re: Disable printf
    ... idea to disable all printf statements so that less memory is required. ... included common header. ... I am using GNU GCC compiler and run the program in both ... Any of you have a suggestion on disabling all printf statements? ...
    (comp.lang.c)
  • Re: HPGCC Questions ladies and gentlemen!!!
    ... :> how to compile it, and that means learning how to use the tools. ... Where did you get the gcc package for windows from? ... :> bit looking for bugs in their beginer level programs with the use of printf ... What kind of program written by beginner is going to "crash"? ...
    (comp.sys.hp48)
  • Re: Making LLVM happy: memmove() in the kernel
    ... be copied by memcpy() which should be faster. ... since _all_ gcc builtins were turned off many years as a side effect ... The gcc builtin for printf() sometimes translates printfto use ...
    (freebsd-arch)
  • Re: x86-64 assembly problems
    ... yasm assembler and link with the gcc. ... in the way simple functions like printf() work with assembly in 64bit ... dword string1; gcc does this when it calls ...
    (alt.lang.asm)
  • Re: STM32 ARM toolset advice?
    ... I haven't seen a commercial compiler that ships the ... By "library" I mean not only the standard C libraries (printf ... implementation) in the bloat of files and directories GCC consists of. ...
    (comp.arch.embedded)