473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing code inside "#if 0"

There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?
I am using SUN compiler.
Nov 13 '05 #1
10 54584


qazmlp wrote:

There are some blocks of C/C++ code put under
#if 0

#end if

Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?

I am using SUN compiler.


No. While it is there the enclosed code will be ignored by the compiler,
so there is nothing in the executable to execute. To run the code you
will have to recompile the program without the "#if 0", or after
changing it to something like "#if 01".

John Howells
Nov 13 '05 #2
In article <db************ *************@p osting.google.c om>,
qazmlp <qa********@red iffmail.com> wrote:
There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?


Why did you use "#if 0" if you meant for it to be an option you could
select at compile time? Change it to something like:

#if DEBUGGING
....
#endif

and then you can use -DDEBUGGING=1 when compiling to enable that block.

--
Barry Margolin, ba************@ level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Nov 13 '05 #3
On Fri, 11 Jul 2003 16:21:04 +0200, Barry Margolin wrote:
In article <db************ *************@p osting.google.c om>, qazmlp
<qa********@red iffmail.com> wrote:
There are some blocks of C/C++ code put under #if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?


Why did you use "#if 0" if you meant for it to be an option you could
select at compile time? Change it to something like:

#if DEBUGGING
...
#endif

and then you can use -DDEBUGGING=1 when compiling to enable that block.

That's a good thing, you even can go further and use
use the symbol NDEBUG as used by the assert macro calls.
In a final/production build, -DNDEBUG is set.
Nov 13 '05 #4
In article <3F************ ***@sun.com>,
Eric Sosman <Er*********@Su n.COM> wrote:
qazmlp wrote:

There are some blocks of C/C++ code put under
#if 0

#end if

Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?

I am using SUN compiler.


tr 0 1 <original.c >tmp.c
mv tmp.c original.c
cc original.c

... and then debug ;-)


Because you need to find all the other funny places where a '0' has been
replaced by a '1' ;-)

--
EMail:jo***@sch ily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js@cs.tu-berlin.de (uni) If you don't have iso-8859-1
sc*******@fokus .fraunhofer.de (work) chars I am J"org Schilling
URL: http://www.fokus.fraunhofer.de/usr/schilling ftp://ftp.berlios.de/pub/schily
Nov 13 '05 #5
bd
On Fri, 11 Jul 2003 03:47:15 -0700, qazmlp wrote:
There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?


Change the #if 0 to #if 1
--
Freenet distribution not available
Grelb's Reminder:
Eighty percent of all people consider themselves to be above
average drivers.

Nov 13 '05 #6
Eric Sosman wrote:
qazmlp wrote:

There are some blocks of C/C++ code put under
#if 0

#end if

Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?

I am using SUN compiler.
tr 0 1 <original.c >tmp.c


Appologies if this is getting too OT, but if you REALLY want to go this route,
then use this translation instead:

sed '/#if/s/0/1/' original.c > tmp.c

so you only translate the zeros on the "#if" lines rather than everywhere in
your program, then do a quick "diff" (or tkdiff if available) on the 2 files to
check the differences before compiling. I'd also keep a backup of original.c
before starting this process!

Ed.
mv tmp.c original.c
cc original.c

... and then debug ;-)

(In other words, no. The compiler is obeying your orders,
and cannot be persuaded to disobey.)

--
Er*********@sun .com


Nov 13 '05 #7
In 'comp.lang.c', qa********@redi ffmail.com (qazmlp) wrote:
There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?


The question is not to be /executed/ of not, but to be *compiled* or not.

The #if 0 trick is used to uncomment easily one or several lines of code.

You could also use a more clever trick that is

#ifndef DBG
#define DBG 0 /* 0 | 1 */
#endif

<...>

#if DBG
/* code to be commented out (or not) */
#endif

Now, some compilers allows you to define a macro on the command line.

Say ...

-DDBG=1
or
-DDBG=0

.... according to your needs.

I often use this trick on embedded systems to reduce the size of some library
code when parts of it are not used.

--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #8
In 'comp.lang.c', Zoran Cutura <zo**********@d aimlerchrysler. com> wrote:
That's a good thing, you even can go further and use
use the symbol NDEBUG as used by the assert macro calls.
In a final/production build, -DNDEBUG is set.


I wouldn't, because obviously this code and assertions are not meant to
be included at the same time.

Actually I'ld probably never use NDEBUG in my code, because this IMHO as
an option from the standard library should only be used for the standard
library.


I don't see why. It often happens that I insert assert() in my code as design
checker, and I'm glad to have it automatically commented out at release time
(final target code). Using assert() implies an implicit use of NDEBUG.

--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #9
In comp.lang.c Emmanuel Delahaye <em**********@n oos.fr> wrote:
In 'comp.lang.c', Zoran Cutura <zo**********@d aimlerchrysler. com> wrote:
That's a good thing, you even can go further and use
use the symbol NDEBUG as used by the assert macro calls.
In a final/production build, -DNDEBUG is set.


I wouldn't, because obviously this code and assertions are not meant to
be included at the same time.

Actually I'ld probably never use NDEBUG in my code, because this IMHO as
an option from the standard library should only be used for the standard
library.


I don't see why. It often happens that I insert assert() in my code as design
checker, and I'm glad to have it automatically commented out at release time
(final target code). Using assert() implies an implicit use of NDEBUG.


You're talking about the implicit usage of NDEBUG? Me not. I mean I
don't do

#ifndef NDEBUG
/* code */
#endif

or

#if !defined NDEBUG
#endif

because I want to be able switch my code on or off separately from
assertions.

--
Z (Zo**********@d aimlerchrysler. com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Nov 13 '05 #10

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

Similar topics

11
4157
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind soul please tell me what I'm doing wrong?
5
5634
by: apple | last post by:
UDBV8 fp 6a - AIX 5.1 We have scheduled cron jobs to do backups. Periodically and starting to occur more frequently, a backup fails with this error: SQL2072N Unable to bind the shared library "". Reason code: "". We are backing up to a file system on the server. Can't find anything in the logs. We can manually resubmit the job 15 or 30...
6
26438
by: Wito | last post by:
hi, I want to backup database (db2, aix 5.1) using script. When I exec script logging to user db2inst1 then is everything ok, but from cron, I get these error: SQL10007N Message "-1390" could not be retrieved. Reason code: "6". Where is the problem?
6
1600
by: swartzbill2000 | last post by:
Hello, I have some downloaded source code on my machine that the .net framework thinks is "not fully trusted". How can I fix this? I assume I use the 'Microsoft .NET Framework 1.1 Configuration' in some way. Bill
3
12002
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type as ODBC, then i am getting
0
1053
by: Angrez Singh | last post by:
Hi, I am trying to use a "customcontrol" inside a "webusercontrol" but facing problem with the viewstate of the "customcontrol". When I use the "customcontrol" on a page either adding it statically or dynamically, it works fine. There is no problem with the ViewState. Also when I use this "customcontrol" inside another "customcontrol"...
1
1246
by: vbfoobar | last post by:
Hello, I have HTML input to which I apply some changes. Feature 1: ======= I want to tranform all the text, but if the text is inside an "a href" tag, I want to leave the text as it is. The HTML is not necessarily well-formed, so
1
1436
by: rashedirshad | last post by:
Is it possible to make a class inside if statement? if true then class a end class end if
2
1756
by: Coreyja | last post by:
I am new to Java and would greatly appreciate any help. Here is some code I am working on as basically a proof of concept. I am using a "throws FileNot FoundException". The problem is that when i run the program nothing happens. There are no errors but there is also no output. This same code worked without the "for" statement for just the first...
0
7852
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...
0
8216
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. ...
1
7974
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...
0
8221
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...
0
6629
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
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...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.