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


|