473,761 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable printf

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?

Dec 1 '06
19 9917
In article <11************ **********@j44g 2000cwa.googleg roups.com>,
RedDevilDan <kl******@yahoo .comwrote:
>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.
If you can add a header to each file, and you are using GCC, you can
put this in it (inside an ifdef that checks for GCC):

extern int printf(const char *format, ...) __attribute__ ((deprecated));

which will result in the message

warning: 'printf' is deprecated

when you compile a file that calls printf.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 1 '06 #11
jaysome <ja*****@spamco p.netwrites:
On 30 Nov 2006 17:58:34 -0800, "RedDevilDa n" <kl******@yahoo .com>
wrote:
>>I am working on a Memory Footprint Reduction project.
<snip>
>>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.
<snip>
The Microsoft Visual C++ compiler provides the /FI compiler option
<snip>
I don't know if gcc has a similar option.
Now OT, but yes, it has -include <fileand the even more useful
-imacros <fileoption.

--
Ben.
Dec 1 '06 #12
jaysome <ja*****@spamco p.netwrites:
If the OP had something like the Microsoft VC++ /FI option, as
described else-thread, he would have intuitively modified a Makefile
file or project file and added a header file and have been done with
it. That's adept, adroit, agile, astute, and, ultimately, awesome.
....and can be rather a surprise when something goes wrong,
because there's nothing in the source code indicating that the
header file gets included.
--
"...deficie nt support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup
Dec 1 '06 #13

"RedDevilDa n" <kl******@yahoo .comwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
>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?
Using a macro to disable printf will not work in the general case.
Suppose you had this:
#define printf(x)
or even using the variadic C99
#define printf(x,...)

But printf is a function that returns an int. Think what will happens if the
code contains:
if ( printf(....) != n ) {...}

One way around this is to add your own printf function that does nothing:

int printf( char *fmt, ... ) {}

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project

Dec 1 '06 #14
Fred Kleinschmidt said:
>
"RedDevilDa n" <kl******@yahoo .comwrote in message
<snip>
>>
Any of you have a suggestion on disabling all printf statements?
<snip>
>
One way around this is to add your own printf function that does nothing:

int printf( char *fmt, ... ) {}
4.1.2 of C89 says: "All external identifiers declared in any of the headers
are reserved, whether or not the associated header is included."

7.1.3 of C99 says: "- Each identifier with file scope listed in any of the
following subclauses (including the future library directions) is reserved
for use as a macro name and as an identifier with file scope in the same
name space if any of its associated headers is included."

So - if you have a C99 compiler, that's fine **provided** that you don't
need anything else from <stdio.h>! But if you don't have a C99 compiler, it
ain't at all fine.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 1 '06 #15
#define printf( f,...) (1)

// or zero, printf can be used in an expression and needs to be an
expression result.
// that's it.

// provided you have a c99 compiler. GCC, OpenWatcom,...

RedDevilDan:
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?
Dec 1 '06 #16
Richard Heathfield wrote:
Fred Kleinschmidt said:

"RedDevilDa n" <kl******@yahoo .comwrote in message

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

One way around this is to add your own printf function that does nothing:

int printf( char *fmt, ... ) {}

4.1.2 of C89 says: "All external identifiers declared in any of the headers
are reserved, whether or not the associated header is included."

7.1.3 of C99 says: "- Each identifier with file scope listed in any of the
following subclauses (including the future library directions) is reserved
for use as a macro name and as an identifier with file scope in the same
name space if any of its associated headers is included."

So - if you have a C99 compiler, that's fine **provided** that you don't
need anything else from <stdio.h>! But if you don't have a C99 compiler, it
ain't at all fine.
7.1.3 of C99 also says "All identifiers with external linkage in any
of the following subclauses (including the future library directions)
are always reserved for use as identifiers with external linkage."

It's not fine in C99, even if you don't use anything from <stdio.h>.

Dec 1 '06 #17
Harald van Dijk said:

<snip>
>
7.1.3 of C99 also says "All identifiers with external linkage in any
of the following subclauses (including the future library directions)
are always reserved for use as identifiers with external linkage."

It's not fine in C99, even if you don't use anything from <stdio.h>.
Good spot. Even without that, it's impractical (because just about every
program needs *something* from stdio.h), but with it, it's a wipe-out.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 1 '06 #18

Richard Heathfield wrote:
Harald van Dijk said:

<snip>

7.1.3 of C99 also says "All identifiers with external linkage in any
of the following subclauses (including the future library directions)
are always reserved for use as identifiers with external linkage."

It's not fine in C99, even if you don't use anything from <stdio.h>.

Good spot. Even without that, it's impractical (because just about every
program needs *something* from stdio.h), but with it, it's a wipe-out.

--
Richard Heathfield
I wonder why no one has suggested the real solution. Replace the
library.
But I guess that solution is really outside the realm of C.

Ed

Dec 1 '06 #19

On Fri, 30 Nov 2006, William Hughes wrote:
RedDevilDan wrote:
>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

Probably no. More likely the problem is that printf is a variadic
function (takes a varying number of arguments) so you need to
replace it a variadic macro.
Probably, the problem is that that line in stdio.h is

extern int printf(const char *fmt, ...);

which --- even with a variadic macro --- will become something like

extern int ((void)0);

which is just plain wrong. The most correct answers, already provided
by other posters, are "don't do that", "get a new library (without
printf)", and "get a new compiler (which can optimize out dead code)".

-Arthur,
intentionally conflating the concepts of "compiler" and "linker"
Dec 2 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5984
by: Bob Bedford | last post by:
I create checkboxes using datas from a database (with PHP). I store all values in an array, as I must pass this value like a Form value. Now, in some cases, when a checkbox is selected, I must disactivate other checkboxes. How can I do this ? here is the code:
6
3165
by: nntp | last post by:
I have a set of links which I want search engines to crawl them, but I want to disable them from my visitors, so I will ask the link owners to pay me to let me enable them. <a disabled href="#">bahbahbah</a> Does not work, as it is still clickable. It only changes the color to grey.
12
8884
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
13
14577
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the textbox enabled and text/background were intact but mouse cursor remained an arraw (as opposed to an I for editable). I tried a Panel control on my .net form since I could I guess there is no longer a frame control (also tried a groupbox control)....
4
3125
by: Chris | last post by:
I have an asp.net page say page1.aspx. The form in html code is <form id = "Form1"> And i want to disable all the fields of the form after some code steps. I had created a javascript funct: function disable() { alert("Forms length is :" + Form1.length); for (i = 0; i < Form1.length; i++) { var formElement = Form1.elements;
0
1805
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a problem while developing some webpages.The Problem is that:- How We Can Disable The Controls Of One Web Form From Other Web Form In Asp.net? Explanation:- There Should Be Two Web Form,Web Form1.aspx and Web Form2.aspx,Now From Web Form1.aspx When I Click One Button (Disable), Then Web Form2.aspx Buttons
4
14250
by: Phoe6 | last post by:
Hi all, I am trying to disable the NIC card (and other cards) enabled in my machine to test diagnostics on that card. I am trying to disable it programmatic using python. I checked python wmi and i could not find ways to disable/enable, (listing is however, possible). Where should I look for to enable/disable devices in python. Thanks,
0
2169
by: sainiranji | last post by:
Hi All I have diffrent categories in diffrrent logging purpose and all are working fine...but now my requirment is to disable all at once . The below are change i did for disable all logges ! Observe log4j parsing this file log4j.debug=false
8
3726
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I disable the right mouse button? ----------------------------------------------------------------------- The oncontextmenu intrinsic event is the only safe and reliable method. Of the other approaches often presented, most depend on an alert box interrupting the process and rarely work. Note that oncontextmenu is a non-standard event and is not...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.