本文介绍了禁用printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个内存占用减少项目。我遇到了一个

的想法来禁用所有printf语句,这样就需要更少的内存。

另外,当没有单个printf语句时,printf

库不会被链接,因此它进一步减少了可执行文件的大小。

是否有一种简单的方法可以在大型项目中禁用printf?在我的

项目中,我们有成千上万的C& C ++文件。他们没有共同的

包括公共标题。否则,我可以在

公共标题中执行#define printf(x)。我正在使用GNU GCC编译器并在
Linux和VxWorks平台上运行该程序。


你们有没有关于禁用所有printf语句的建议?


我还考虑在整个项目中添加一个公共头文件。

但是,我需要放一个#include" common.h"排成每个c

文件。要做那件事还需要一段时间。有没有办法在每个c文件中自动插入



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?

推荐答案



这当然是关于工具集,而不是关于C语言。


< OT>


一些随机的想法。


您可以使用gcc'的-D''name(args ..)= definition''选项。

根据事情的排列方式,你可能能够使用路径来代替gcc,或者你可能需要使用PATH来玩游戏。和
二进制可执行文件的名称。


您可以使用自己喜欢的脚本语言

插入行#include" COMMON.H"在任何文件的开头

结束" .c"或cpp。或者你可以通过编译

a文件编译generic.c包含


#include" common.h"

#include" ; generic.c"


再次,你应该能够将它包装在脚本中,称之为gcc,更改

PATH变量以便你的gcc首先调用

actual_gcc到/ usr / bin / gcc并从srcipt中调用actual_gcc。

然后当makefile调用gcc时,它们将获得你的版本


< / OT>

- William Hughes


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





这当然是关于工具集,而不是关于C语言。


< OT>


一些随机的想法。


你或许可以使用gcc'的-D''name(args ..)=定义''选项。

根据事情的排列方式,你可能能够用bcc替换gcc,或者你可能不得不用PATH来玩游戏。和
二进制可执行文件的名称。


您可以使用自己喜欢的脚本语言

插入行#include" COMMON.H"在任何文件的开头

结束" .c"或cpp。或者你可以通过编译

a文件编译generic.c包含


#include" common.h"

#include" ; generic.c"


再次,你应该能够将它包装在脚本中,称之为gcc,更改

PATH变量以便你的gcc首先调用

actual_gcc到/ usr / bin / gcc并从srcipt中调用actual_gcc。

然后当makefile调用gcc时,它们将获得你的版本


< / OT>

- William Hughes



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




请不要过头。请阅读以下内容:




我确定你可以使用某种脚本添加#includecommon。 H"你的每个源文件都是
,但这是一个不同的

新闻组的问题。如果您使用的是类Unix系统,请尝试comp.unix.shell或

comp.unix.programmer。


-

Keith Thompson(The_Other_Keith)< http://www.ghoti.net / ~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

Please don''t top-post. Read the following:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

I''m sure you can use some kind of script to add #include "common.h" to
each of your source files, but that''s a question for a different
newsgroup. If you''re on a Unix-like system, try comp.unix.shell or
comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于禁用printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 09:33