º¥ýøª¾ÂI¸Ñ«Ydev-cpp °õ¦æ, ½Ðpost ®Id error ¦Pwarning message o¾¤Ú»¤U.
¥¨¶°¬O«D±`¦³¥Îªº, ¥ýnª¾¹D¥¨¶°¬O¤°»ò, ¥¦¬O¦bcompile time ªº®ÉÔ´N¨M©w¨º¤@¥ycode ncompile, ¨º¤@¥y¤£¥Îcompile, ¨ú¨M©ó§AÂI¼Ëset Ómacro. ¦Ó³oÓ¤èªk¦P§A¥Î"if ... else" «Y¦³¤À§O, ¤À§O¦b©ó¤@Ó«Ycompile time ´N¨M©w¦æÃä¤@¥y, ¥t¤@Ó´N«Yrun time. compile time ¥h¨M©w´N§Q¥Î¥¨¶°, ³o¼Ë¦³¥H¤U¦n³B:
1. ¤£¦Pª©¥»³B²z/µo©ñ:
Á|Ó¨Ò, ·í§Anµ¹«È¤H§Aªºµ{¦¡®É, §A·|¦³¼w°ê«È¤H, ¬ü°ê«È¤H, ·ç¨å«È¤H, ¥LÌnªº»y¨¥¬O¤j¤£¦Pªº, ¨º§A¥i¥H¥Î¤£¦Pcompile macro definition ¥hbuild ¤£¦Pªºª©¥»µ¹«È¤H, ¦Ó¥L̪ºbuild ùرµ´¹ï¤£·|¦³¨ä¥Lª©¥»ªº²ª¸ñ. build ¥X¨Óªºµ{¦¡size ¥ç¤£·|«Ü¤j, ¦]¬°compiler ¥u·|compile Ãö©óoӺػy¨¥ªºcode. e.g.
#ifdef _BUILD_GERMAN
printf("Aaa");
#elseif _BUILD_USA
printf("Bbb");
#elseif _BUILD_SWZLAND
printf("Ccc");
#endif
2. ¤£¦Pos platform
¦bÁ|Ó¨Ò¤l, ·í§Aªºbuild n«Yhardware ©ÎªÌ os dependent, ËÝ¥i¯àinteger «Ylinux «Y1 byte, ¦ý«Ywindows «Y2byte ËÝ°Õ, §A·|¥Îmacro ¥h¤À:
#ifdef _OS_WINDOWS_
typedef u_16 int
#elseif _OS_LINUX_
typedef u_8 int
#endif
·íµM, ¹ê»Ú±¡ªpø«Y1byte ¦P2byte °Õ ... ¦ýËݼ˴N¥i¥H°µ¨ì§Aªºbuild ¥i¥Hcross platform Ëݦæ, ¥un§Acompile ªº®ÉÔdefine ø¦Pmacro ´N±o
¥ò¦³¦n¦h¨Ò¤lÃö©ó¥Îmacro °µcross platform ¬[, ¨Ò¦p§A¦æsemphore, ©ÎªÌmutex, ¤x¸g«Yø¦Pos , ´N¦³ø¦Papi, ¦ýÊ\¦a°µªºfunction ¤@¼Ë:
void MyCreateThread(...)
{
#ifdef _OS_WINDOWS_
CreateThread(...);
#elseif _OS_LINUX_
p_thread_create(...);
#endif
}
ËݼË, §AÓmyCreateThread(...) ´N¥i¥H©ð¥hlinux, ©ÎªÌwindow ¦æ°Õ, ¥un§Acompile ®Éset ²M·¡§Aªºmacro ...
3. debug msg build
¥ò¦³´N«Y, ·í§Andebug §AÓprogram, ³q±`§A³£·|¥[¤@d printf, ¦ý·ínreleaes Úd «È, §A´N·|§R°£®Í, ËÝø³q§A¯u«Y¨C¤@¥y¥h§R«§... ¦pªG¥Îmacro:
#ifdef _debug_
printf(...);
#endif
ËݧA´N¦n®e©öËÝ, ¥i¥H "keep" ¦íd debug code, ¦ý«Yrelease ®É, ¥unundefine µfÓ_debug_, §A´N¥i¥H¦n»´©öËÝ"§R°£" ®Í©Ò¦³printf debug code, ¦]¬°©Ò¦³Ú_debug_ ¥]¦íªºcode ¤x¸gø·|¹Lcompiler ...³Ì«áÓbuild ³£·|²Ó¦n¦h, ©OÓ¥ç«YÂI¸Ñ«Yvc6, §Abuild Ódebug build ¦Prelease build ®É¤j¤p¤£¦Pªºì¦] ...
macro ¥i¥HËÝÁ¿, «Y¥Îo¾¤°µcode management ªº ~
§Úø¤Ó¼ôjava ©ÎªÌvb, øª¾¨ä¥Llanguage ¦³ÉN©OÃþ¥\¯à©O?
[ ¥»©«³Ì«á¥Ñ hhl ©ó 2006-11-27 04:31 AM ½s¿è ]
¬ÛÃö·j¯Á¥Ø¿ý: »y¨¥