Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > Re: debug using...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 955 of 1041
Post > Topic >>

Re: debug using #ifdef

by Tomasz bla Fortuna <bla@[EMAIL PROTECTED] > Feb 12, 2008 at 08:56 PM

Dnia Tue, 12 Feb 2008 10:36:55 -0800 (PST)
YL <elim.qiu@[EMAIL PROTECTED]
> napisa=B3(a):

> Hopefully it's ok to ask the following here:
>=20
> I saw some code like
>=20
> #ifdef DEBUG
>                 NSLog(@[EMAIL PROTECTED]
"ContentSections now [%@[EMAIL PROTECTED]
",contentSections);
> #endif
>=20
> and wondering how this work
>=20
> anywhere 'DEBUG' shall be defined?
>=20
> Thanks for help
>=20
As this is general C question I can help a bit.

When using #ifdef name ... #endif code is used only when you define
somewhere that 'name'.=20

You can do it like this:
#define DEBUG

Or by passing options to compiler (-D for gcc AFAIK).

However it's much better to do this like this:

#define DEBUG

#ifdef DEBUG
#	undef DEBUG
#	define DEBUG 1
#else
#	define DEBUG 0
#endif

(Or just define DEBUG as 1 or 0) and then:
if (DEBUG) {
	Code used for debugging.
}=20

This method allows compiler to do more semanticall checks, therefore is
safer. Good compiler will remove all code and condition if DEBUG is set
to 0, so it's not a problem...

Go read something about preprocessor... ;)

see you,
--=20
Tomasz bla Fortuna
jid: bla(at)af.gliwice.pl
pgp: 0x90746E79 @[EMAIL PROTECTED]
 pgp.mit.edu
www: http://bla.thera.be
 




 4 Posts in Topic:
debug using #ifdef
YL <elim.qiu@[EMAIL PR  2008-02-12 10:36:55 
Re: debug using #ifdef
Tomasz bla Fortuna <bl  2008-02-12 20:56:37 
Re: debug using #ifdef
YL <elim.qiu@[EMAIL PR  2008-02-12 12:55:40 
Re: debug using #ifdef
Filipe Cabecinhas <fil  2008-06-07 20:30:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 11:07:28 CDT 2008.