锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品亚洲AV久久久无码,99久久精品国内,国产精品岛国久久久久 http://www.shnenglu.com/sandy/category/767.html楂樻ц兘鏈嶅姟鍣ㄧ璁$畻 zh-cn Mon, 04 Jun 2012 01:32:26 GMT Mon, 04 Jun 2012 01:32:26 GMT 60 閫嗗悜涓夊浗緹よ嫳2 http://www.shnenglu.com/sandy/archive/2012/05/31/176971.html灝忔槑 灝忔槑 Thu, 31 May 2012 13:53:00 GMT http://www.shnenglu.com/sandy/archive/2012/05/31/176971.html http://www.shnenglu.com/sandy/comments/176971.html http://www.shnenglu.com/sandy/archive/2012/05/31/176971.html#Feedback 1 http://www.shnenglu.com/sandy/comments/commentRss/176971.html http://www.shnenglu.com/sandy/services/trackbacks/176971.html 闂叉潵鏃犱簨錛屾悶鎼為嗗悜宸ョ▼鍒嗘瀽涓涓嬩笁鍥界兢鑻?/span>2錛屼粖澶╃殑鐩爣鏄幓鎺夊厜鐩樻彁紺?騫惰娓告垙姝e父榪涜銆傚洜涓烘垜鐜╃殑鏄師鐗堬紝鎵浠ユ瘡褰撶洿鎺ヨ繍琛宻ango2.exe浼氬脊鍑哄涓嬪璇濇:
鎴戜嬌鐢ㄧ殑宸ュ叿鏄ぇ鍚嶉紟榧庣殑OllyDBG銆?/span>
棣栧厛錛屾墦寮OD,鎵撳紑sango2.exe, 榪愯紼嬪簭錛屽綋鍑虹幇瀵硅瘽妗嗘椂鏆傛椂紼嬪簭錛屽彂鐜板仠鍦ㄦ澶勶細
浠旂粏鐪嬩互涓嬪嚑琛屼唬鐮侊紝鍙互鐪嬪嚭鍦?0B207澶勬湁涓涓垽鏂紝濡傛灉EAX=0錛屽垯涓嶆樉紺哄璇濇錛屽茍璺寵漿鍒?0B21F錛岄偅濡傛灉鎴戜滑鎶夿207鐨?#8220;JE SHORT 0040B21F”鏀逛負“JNE SHORT 0040B21F”,鏄惁灝卞彲浠ヤ笉鏄劇ず瀵硅瘽妗嗗憿錛熺粡嫻嬭瘯錛岀‘瀹炰笉鏄劇ず浜嗭紝浣嗘槸娓告垙涔熺洿鎺ラ鍑轟簡錛屽茍娌℃湁杈懼埌鎴戜滑瑕佺殑鏁堟灉銆傜湅鏉ヨ繖涓湴鏂瑰彧鏄嚭閿欏悗鐨勭▼搴忓鐞嗭紝鎴戜滑瑕佹壘鍒版洿娣辯殑婧愬ご錛屾墠鑳借В鍐寵繖涓棶棰樸?/span>
涓婃柇鐐癸紒鎴戜滑瑕佺粨鍚堝崟姝ヨ皟璇曟潵鐞嗚В紼嬪簭鐨勮繍琛岄昏緫鎵嶈兘鍙戠幇鐪熸鐨勮В鍐蟲柟妗堛?/span>
瑙傚療瀵硅瘽妗嗗嚭鐜扮殑鏃跺欙紝紼嬪簭鐨勫爢鏍堝涓嬶細
鍙戠幇榪欎釜鍑芥暟鐨勫叆鍙e湪 40B00A錛屾垜浠湪姝よ緗柇鐐瑰紑濮嬪崟姝ヨ皟璇曪紝浼氬彂鐜板湪璋冪敤4300F0鍑虹幇瀵硅瘽妗嗭紝璺熻釜榪涘幓銆?/span>
鐢ㄨ繖鏍風殑鏂規硶璺熻釜榪涘幓錛屼繚鎸佽愬績鍜屾竻閱掔殑澶磋剳錛屾渶緇堜細鍙戠幇 4302C8浼氳繘琛岄敊璇鐞嗭紝瀵艱嚧瀵硅瘽妗嗙殑鍑虹幇錛屽彧瑕佽煩榪囧嵆鍙傛垜浠慨鏀?302C1鐨勪唬鐮佷負"JZ short 004302D1"錛屽嵆鍙煩榪囧璇濇錛岀洿鎺ヨ繘琛屾父鎴忋?/span>
鏈鍚庝竴姝ワ紝鍑鴻ˉ涓併備嬌鐢ㄥ彸閿姛鑳姐?/span>copy to executable銆戯紝鐒跺悗鍙﹀瓨涓哄彲鎵ц鏂囦歡灝卞彲浠ヤ簡銆傝繍琛屼慨鏀硅繃鍚庣殑sango2.exe錛屽氨浼氬彂鐜板凡緇忕牬瑙f垚鍔熶簡銆?/span>
]]>debug to fix crash http://www.shnenglu.com/sandy/archive/2012/04/27/172918.html灝忔槑 灝忔槑 Fri, 27 Apr 2012 07:34:00 GMT http://www.shnenglu.com/sandy/archive/2012/04/27/172918.html http://www.shnenglu.com/sandy/comments/172918.html http://www.shnenglu.com/sandy/archive/2012/04/27/172918.html#Feedback 4 http://www.shnenglu.com/sandy/comments/commentRss/172918.html http://www.shnenglu.com/sandy/services/trackbacks/172918.html 闃呰鍏ㄦ枃 ]]> 閭d簺leveldb浣跨敤鐨勫鎶娣閥1-鍐呭瓨綆$悊 http://www.shnenglu.com/sandy/archive/2012/03/28/leveldb-trick1.html灝忔槑 灝忔槑 Wed, 28 Mar 2012 10:00:00 GMT http://www.shnenglu.com/sandy/archive/2012/03/28/leveldb-trick1.html http://www.shnenglu.com/sandy/comments/169303.html http://www.shnenglu.com/sandy/archive/2012/03/28/leveldb-trick1.html#Feedback 1 http://www.shnenglu.com/sandy/comments/commentRss/169303.html http://www.shnenglu.com/sandy/services/trackbacks/169303.html 闃呰鍏ㄦ枃 ]]> 濂囨殑g++鐨勮涓?/title> http://www.shnenglu.com/sandy/archive/2008/08/13/58733.html灝忔槑 灝忔槑 Wed, 13 Aug 2008 08:56:00 GMT http://www.shnenglu.com/sandy/archive/2008/08/13/58733.html http://www.shnenglu.com/sandy/comments/58733.html http://www.shnenglu.com/sandy/archive/2008/08/13/58733.html#Feedback 18 http://www.shnenglu.com/sandy/comments/commentRss/58733.html http://www.shnenglu.com/sandy/services/trackbacks/58733.html 闃呰鍏ㄦ枃 ]]> printf鐨剋rapper http://www.shnenglu.com/sandy/archive/2007/10/12/34022.html灝忔槑 灝忔槑 Fri, 12 Oct 2007 06:13:00 GMT http://www.shnenglu.com/sandy/archive/2007/10/12/34022.html http://www.shnenglu.com/sandy/comments/34022.html http://www.shnenglu.com/sandy/archive/2007/10/12/34022.html#Feedback 0 http://www.shnenglu.com/sandy/comments/commentRss/34022.html http://www.shnenglu.com/sandy/services/trackbacks/34022.html 闃呰鍏ㄦ枃 ]]> 濡備綍鍐欏嚭涓撲笟鐨凜澶存枃浠?/title> http://www.shnenglu.com/sandy/archive/2007/05/15/24151.html灝忔槑 灝忔槑 Tue, 15 May 2007 05:38:00 GMT http://www.shnenglu.com/sandy/archive/2007/05/15/24151.html http://www.shnenglu.com/sandy/comments/24151.html http://www.shnenglu.com/sandy/archive/2007/05/15/24151.html#Feedback 7 http://www.shnenglu.com/sandy/comments/commentRss/24151.html http://www.shnenglu.com/sandy/services/trackbacks/24151.html 闃呰鍏ㄦ枃 ]]> C++婧愭枃浠剁紪鐮侀棶棰?/title> http://www.shnenglu.com/sandy/archive/2007/04/05/21320.html灝忔槑 灝忔槑 Thu, 05 Apr 2007 07:30:00 GMT http://www.shnenglu.com/sandy/archive/2007/04/05/21320.html http://www.shnenglu.com/sandy/comments/21320.html http://www.shnenglu.com/sandy/archive/2007/04/05/21320.html#Feedback 6 http://www.shnenglu.com/sandy/comments/commentRss/21320.html http://www.shnenglu.com/sandy/services/trackbacks/21320.html 闃呰鍏ㄦ枃 ]]> {Just for fun} 濡備綍璁╂寚閽堟寚鍚戣嚜宸?/title> http://www.shnenglu.com/sandy/archive/2007/04/04/21229.html灝忔槑 灝忔槑 Wed, 04 Apr 2007 04:16:00 GMT http://www.shnenglu.com/sandy/archive/2007/04/04/21229.html http://www.shnenglu.com/sandy/comments/21229.html http://www.shnenglu.com/sandy/archive/2007/04/04/21229.html#Feedback 8 http://www.shnenglu.com/sandy/comments/commentRss/21229.html http://www.shnenglu.com/sandy/services/trackbacks/21229.html 闃呰鍏ㄦ枃 ]]> [STL] 寰幆涓璭rase http://www.shnenglu.com/sandy/archive/2006/12/27/16913.html灝忔槑 灝忔槑 Wed, 27 Dec 2006 10:01:00 GMT http://www.shnenglu.com/sandy/archive/2006/12/27/16913.html http://www.shnenglu.com/sandy/comments/16913.html http://www.shnenglu.com/sandy/archive/2006/12/27/16913.html#Feedback 11 http://www.shnenglu.com/sandy/comments/commentRss/16913.html http://www.shnenglu.com/sandy/services/trackbacks/16913.html 闃呰鍏ㄦ枃 ]]> 璋堣皥snprintf http://www.shnenglu.com/sandy/archive/2006/09/29/13133.html灝忔槑 灝忔槑 Fri, 29 Sep 2006 02:27:00 GMT http://www.shnenglu.com/sandy/archive/2006/09/29/13133.html http://www.shnenglu.com/sandy/comments/13133.html http://www.shnenglu.com/sandy/archive/2006/09/29/13133.html#Feedback 7 http://www.shnenglu.com/sandy/comments/commentRss/13133.html http://www.shnenglu.com/sandy/services/trackbacks/13133.html 闃呰鍏ㄦ枃 ]]> STL 澶囧繕褰?/title> http://www.shnenglu.com/sandy/archive/2006/07/12/9721.html灝忔槑 灝忔槑 Wed, 12 Jul 2006 03:19:00 GMT http://www.shnenglu.com/sandy/archive/2006/07/12/9721.html http://www.shnenglu.com/sandy/comments/9721.html http://www.shnenglu.com/sandy/archive/2006/07/12/9721.html#Feedback 14 http://www.shnenglu.com/sandy/comments/commentRss/9721.html http://www.shnenglu.com/sandy/services/trackbacks/9721.html 闃呰鍏ㄦ枃 ]]> G11N Developement (2) --- Linux Best Practice http://www.shnenglu.com/sandy/archive/2006/06/26/9020.html灝忔槑 灝忔槑 Mon, 26 Jun 2006 08:57:00 GMT http://www.shnenglu.com/sandy/archive/2006/06/26/9020.html http://www.shnenglu.com/sandy/comments/9020.html http://www.shnenglu.com/sandy/archive/2006/06/26/9020.html#Feedback 0 http://www.shnenglu.com/sandy/comments/commentRss/9020.html http://www.shnenglu.com/sandy/services/trackbacks/9020.html ftp://ftp.gnu.org/gnu/gettext/ ) 鍜宭ibiconv(http://www.gnu.org/software/libiconv/ ) ,鍓嶈呮槸鐢ㄤ簬瀹炵幇Resource bundle,鑰屽悗鑰呯敤浜庡悇縐嶇紪鐮佽漿鍖栥?br> (娉?榪欓噷娌℃湁鑰冭檻cross-platform) 1. 瀹炵幇鏂規硶 a . 浣跨敤po鏂囦歡浣滀負璧勬簮鏂囦歡 (寤鴻緙栫爜鏄痷tf-8) 涓鏂歸潰鍥犱負UTF-8鍏煎ANSI,鍙﹀涓鏂歸潰鑰冭檻鍒癎11N鐨勭▼搴忓ぇ閮ㄥ垎浣跨敤utf-8杈撳嚭錛屾瘮濡傝緭鍑哄埌database,web UI, file絳夌瓑銆?br> b. 浣跨敤getext浠巖esource file ( mo鏂囦歡)璇誨埌鐩稿簲鐨凩10N resource鏂囦歡 娉ㄦ剰榪欓噷闇瑕佸厛setlocale鏉ヨ緗甽ocale
#include < stdio.h > #include < locale.h > #include < libintl.h > #define _(string) gettext (string) int main( int argc, char ** argv) { if (setlocale(LC_ALL, “”) == NULL) { fprintf(stderr, “setlocale() error.\n”); return - 1 ; } if (bindtextdomain(package, “ / usr / share / locale”) == NULL) { fprintf(stderr, “bindtextdomain() error.\n”); return – 1 ; } if (textdomain(package) == NULL) { fprintf(stderr, “textdomain() error.\n”); return – 1 ; } printf(“ % s\n”, _(“Hello, world ! ”)); return 0 ; }
c.濡傛灉瑕佽緭鍑哄埌鎺у埗鍙?console),鍥犱負涓嶆槸console閮芥敮鎸乽nicode output錛屾墍浠ユ帹鑽愮殑鏂規硶鏄鍏堟槸鎶妘tf-8杞寲涓烘湰鍦扮紪鐮侊紝鐒跺悗浣跨敤printf杈撳嚭銆備笉鎺ㄨ崘浣跨敤wprintf榪涜杈撳嚭錛屼竴鏂歸潰鏄洜涓簑char_t鐨勫ぇ灝忛殢緙栬瘧鍣ㄤ笉鍚岋紝涓嶅ソ鎺у埗銆傚彟澶栦竴鏂歸潰錛屽緢澶歸printf鐨勫疄鐜頒篃閮芥槸鍏堟妸wchar_t[]杞負鏈湴緙栫爜錛岀劧鍚庤緭鍑恒傝漿鍖栫紪鐮佷嬌鐢╨ibconv d.濡傛灉瑕佽緭鍑哄埌web pages,database,file錛岀紪鐮佹帹鑽愪嬌鐢╱tf-8. e.濡傛灉瑕佽緭鍑烘湰鍦板寲鐨勬棩鏈熷拰鏃墮棿錛屼嬌鐢ˋPI: strftime
#include < stdio.h > #include < time.h > int main( int argc, char ** argv) { time_t t; struct tm * ptm; char buffer[ 100 ]; memset(buffer, 0 , sizeof (buffer)); if (time( & t) < 0 ) { fprintf(stderr, “time() error: % m\n”); } if ((ptm = localtime( & t)) == NULL) { fprintf(stderr, “localtime() error: % m\n”); } strftime(buffer, sizeof (buffer), “ % x % X”, ptm); printf(“ % s\n”, buffer); return 0 ; }
f. 濡傛灉瑕佽緭鍑烘湰鍦板寲鐨勬暟瀛楀拰璐у竵錛屼嬌鐢ˋPI: strfmon
#include < stdio.h > #include < monetary.h > int main( int argc, char ** argv) { char buffer[ 100 ]; strfmon(buffer, sizeof (buffer), “ %=* i " , 12345.67); printf(“ % s\n”, buffer); return 0 ; }
2.鐩綍緇撴瀯 /product /i18n /zh_TW your.mo /ja_JP your.mo ]]> 娣卞叆 printf / wprintf / console涓嬬殑unicode output http://www.shnenglu.com/sandy/archive/2006/06/21/8779.html灝忔槑 灝忔槑 Wed, 21 Jun 2006 03:53:00 GMT http://www.shnenglu.com/sandy/archive/2006/06/21/8779.html http://www.shnenglu.com/sandy/comments/8779.html http://www.shnenglu.com/sandy/archive/2006/06/21/8779.html#Feedback 5 http://www.shnenglu.com/sandy/comments/commentRss/8779.html http://www.shnenglu.com/sandy/services/trackbacks/8779.html 渚嬪:wchar_t聽test[] = L " 嫻嬭瘯1234 " ; printf( " %s " ,test);
鏄笉浼氭紜緭鍑虹殑 2.wprintf 鍚屾牱涓嶄細鎻愪緵unicode output, 聽聽 浣嗘槸浠栦細鎶妛char_t鐨剆tring杞負locale鐨凷B/MB瀛楃緙栫爜錛岀劧鍚庤緭鍑?br />渚嬪錛?br />wchar_t聽test[]聽 = 聽L " 嫻嬭瘯Test " ; wprintf(L " %s " ,test);
浼氳緭鍑??1234涔嬬被鐨勫瓧絎︿覆錛屾垨鑰呬笉杈撳嚭浠諱綍緇撴灉 鍥犱負wprintf娌℃湁鍔炴硶鎶奓"嫻嬭瘯Test"杞負榛樿鐨凙NSI,闇瑕佽緗甽ocalesetlocale(LC_ALL, " chs " ); wchar_t聽test[]聽 = 聽L " 嫻嬭瘯Test " ; wprintf(L " %s " ,test);
浼氭湁姝g‘鐨勮緭鍑?br />絳夊悓浜巔rintf("%ls",test); 緇間笂:聽 CRT I/O functions do not provide Unicode output. 3. Window console鑷粠NT4灝辨槸涓涓湡姝g殑unicode console 涓嶈繃杈撳嚭unicode string,鍙湁浣跨敤Windows API, WriteConsoleW 渚嬪錛?br />wchar_t聽test[]聽 = 聽L " 嫻嬭瘯1234 " ; DWORD聽ws; WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),test,wcslen(test), & ws,NULL);
鍙互姝g‘鐨勮緭鍑鴻屼笉闇瑕佽緗甽ocale,鍥犱負鏄湡姝g殑unicode鐨勮緭鍑猴紝璺焎odepage鏃犲叧 4. 濡備綍瀹炵幇璺ㄥ鉤鍙扮殑console output 聽聽聽 涓嶈浣跨敤wchar_t鍜寃printf,鍥犱負榪欎簺閮戒緷璧栦簬緙栬瘧鍣? 聽聽聽聽 ICU鏄疘BM鐨勪竴涓垚鐔熺殑璺ㄥ鉤鍙版敮鎸乽nicode鐨刲ibary,鎺ㄨ崘浣跨敤 浠ヤ笅鏄疘CU鐨剈printf瀹炵幇void 聽uprintf( const 聽UnicodeString聽 & str)聽{ 聽聽聽聽 char 聽 * buf聽 = 聽 0 ; 聽聽聽聽int32_t聽len聽 = 聽str.length(); 聽聽聽聽int32_t聽bufLen聽 = 聽len聽 + 聽 16 ; 聽聽聽聽int32_t聽actualLen; 聽聽聽聽buf聽 = 聽 new 聽 char [bufLen聽 + 聽 1 ]; 聽聽聽聽actualLen聽 = 聽str.extract( 0 ,聽len,聽buf /* ,聽bufLen */ );聽 // 聽Default聽codepage聽conversion 聽聽聽聽buf[actualLen]聽 = 聽 0 ; 聽聽聽聽printf( " %s " ,聽buf); 聽聽聽聽delete聽buf; }
瀹冧篃鏄厛鎶奤nicode string杞寲涓烘湰鍦扮殑codepage,鐒跺悗printf錛岃櫧鐒朵篃涓嶆槸unicode output,浣嗘槸璺ㄥ鉤鍙幫紝澶у鏁版儏鍐典細宸ヤ綔寰楀緢濂姐?br /> ]]> G11N Development(1) --- Unicode Basic && wxxx function http://www.shnenglu.com/sandy/archive/2006/06/19/8722.html灝忔槑 灝忔槑 Mon, 19 Jun 2006 11:45:00 GMT http://www.shnenglu.com/sandy/archive/2006/06/19/8722.html http://www.shnenglu.com/sandy/comments/8722.html http://www.shnenglu.com/sandy/archive/2006/06/19/8722.html#Feedback 1 http://www.shnenglu.com/sandy/comments/commentRss/8722.html http://www.shnenglu.com/sandy/services/trackbacks/8722.html 闃呰鍏ㄦ枃 ]]> 婕皥鍑芥暟鐨勮繑鍥炲?/title> http://www.shnenglu.com/sandy/archive/2006/04/25/6252.html灝忔槑 灝忔槑 Tue, 25 Apr 2006 08:55:00 GMT http://www.shnenglu.com/sandy/archive/2006/04/25/6252.html http://www.shnenglu.com/sandy/comments/6252.html http://www.shnenglu.com/sandy/archive/2006/04/25/6252.html#Feedback 2 http://www.shnenglu.com/sandy/comments/commentRss/6252.html http://www.shnenglu.com/sandy/services/trackbacks/6252.html 1 . 榪斿洖闈?琛ㄧず鎴愬姛錛岃繑鍥?琛ㄧず澶辮觸 澶у鏁癢in32 Platform API閮芥槸榪欐牱,姣斿int 聽result聽 = MoveFileEx(szTempName,聽 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 " allcaps.txt " ,聽 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽MOVEFILE_REPLACE_EXISTING); if ( ! result) 聽聽聽聽{聽 聽聽聽聽聽聽聽聽printf( " Could聽not聽move聽file.聽error:%d " ,GetLastError()); 聽聽聽聽聽聽聽聽 return 聽 0 ; 聽聽聽聽}
浣跨敤榪欑鏂規硶銆備綘蹇呴』鎻愪緵綾諱技GetLastError鐨勫彇閿欒鐨勬柟娉曪紝鑰屼笖浣犲繀欏諱繚璇佽繖涓嚱鏁版槸thread-safe鐨勶紝姣忎釜綰跨▼鑳界淮鎶よ嚜宸辯殑閿欒淇℃伅銆?br />2. 榪斿洖澶т簬絳変簬0琛ㄧず鎴愬姛錛岃繑鍥?1琛ㄧず澶辮觸 socket api澶ч儴鍒嗘槸榪欐牱璁捐鐨?br />while (聽bytesRecv聽 != 聽SOCKET_ERROR聽)聽{ 聽聽聽聽bytesRecv聽 = 聽recv(聽ConnectSocket,聽recvbuf,聽 32 ,聽 0 聽); 聽聽聽聽 if 聽(聽bytesRecv聽 == 聽 0 聽 || 聽bytesRecv聽 == 聽WSAECONNRESET聽)聽{ 聽聽聽聽聽聽printf(聽 " Connection聽Closed.\n " ); 聽聽聽聽聽聽 break ; 聽聽聽聽} 聽聽聽聽printf(聽 " Bytes聽Recv:聽%ld\n " ,聽bytesRecv聽); 聽聽}
榪欐牱鐨勫ソ澶勬槸榪斿洖鍊煎氨鍙互鐢ㄦ潵琛ㄧず鎴愬姛鍜岀姸鎬併傛瘮濡傝繖閲岀殑recv灝卞彲浠ヨ繑鍥炴敹鍒扮殑瀛楄妭鏁般備絾鏄綘榪樻槸瑕佹湁涓涓煡璇㈤敊璇殑API,like WSAGetLastError().3.榪斿洖0琛ㄧず鎴愬姛 COM鐨勬帴鍙eぇ閮ㄥ垎鏄繖鏍瘋璁$殑if (聽FAILED(lpdd -> QueryInterface(IID_IDirectDraw7,聽(LPVOID聽 * )聽 & lpdd))) 聽聽聽聽{ 聽聽聽聽聽聽聽聽聽聽 // error聽handle聽and聽return 聽聽聽聽}
鍏朵粬鐨勪竴浜涜冭檻1.濡備綍瀹氫箟閿欒鍊鹼紵 綆鍗曠殑涓鐐逛嬌鐢ㄥ畯榪炵畫瀹氫箟錛宭ike#define 聽E_NO_FILE聽1 #define 聽E_BAD_FILE聽2
澶嶆潅鐨勪竴鐐瑰氨鍍廋OM錛屼弗鏍肩殑瀹氫箟姣忎竴浣嶇殑鎰忎箟 榪欑鎯呭喌涓嬩綘鍙互鎻愪緵涓涓畯鏉ュ垱寤洪敊璇唬鐮?like#define 聽MAKE_HRESULT(sev,fac,code)\ (聽(HRESULT)聽(((unsigned聽long )(sev) << 31 )聽 | 聽((unsigned聽 long )(fac) << 16 )聽\ | 聽((unsigned聽 long )(code)))聽)
2.鍙互鎻愪緵涓涓畯鎴栬呭嚱鏁版潵甯姪鍒ゆ柇鏄惁鎴愬姛 姣斿COM鎻愪緵浜咶AILED瀹忔潵甯姪浣犲垽鏂瑿OM鐨勮繑鍥炲?br />#define 聽FAILED(Status)聽聽聽聽聽((HRESULT)(Status)<0)
3.濡傛灉鍙湁閿欒鍜屾垚鍔熶袱涓繑鍥炲?鑰冭檻浣跨敤bool鏉ヨ繑鍥?br /> 榪欎釜閫傜敤浜嶤++,浼樼偣鏄剰涔夊緢娓呮櫚.榪斿洖 true灝辨槸鎴愬姛,false灝辨槸澶辮觸.4.瑕佷嬌鐢ㄥ紓甯告潵琛ㄧず閿欒鐨勭姸鎬佷箞? 浣跨敤寮傚父鐨勫ソ澶勫氨鏄繑鍥炲艱鐪佸嚭鏉ヤ簡錛屽彲浠ヤ笉榪斿洖鎴栬呰繑鍥炲叾浠栦俊鎭紝榪樻湁鐩婁簬瀹氫箟閿欒綾誨瀷鍜岀畝鍖栫▼搴忔祦紼嬨傜己鐐瑰氨鏄疌++瀵瑰紓甯告敮鎸佽繕涓嶅濂?娌℃湁finally,姣忎竴瀹剁紪璇戝櫒鏀寔涔熶笉涓鏍?瀹炵幇鍙兘澶т笉鍚? ]]> Is it a vc6 bug? http://www.shnenglu.com/sandy/archive/2006/04/24/6195.html灝忔槑 灝忔槑 Mon, 24 Apr 2006 10:08:00 GMT http://www.shnenglu.com/sandy/archive/2006/04/24/6195.html http://www.shnenglu.com/sandy/comments/6195.html http://www.shnenglu.com/sandy/archive/2006/04/24/6195.html#Feedback 21 http://www.shnenglu.com/sandy/comments/commentRss/6195.html http://www.shnenglu.com/sandy/services/trackbacks/6195.html
#include聽
<
stdio.h
>
int
聽main() { 聽聽聽聽
int
聽a
=
10
,b
=
20
; 聽聽聽聽a
=
(a
+
b)
-
(b
=
a); 聽聽聽聽printf(
"
a=%d,b=%d\n
"
,a,b); 聽聽聽聽 聽聽聽聽
return
聽
0
; }
寰堢畝鍗曪紝浜ゆ崲a鍜宐鐨勫?br /> 鍦╠ebug妯″紡涓嬶紝杈撳嚭 a=20,b=10 鍦╮elease妯″紡涓嬶紝杈撳嚭 a=10,b=10I think there is a bug in release version. ]]> C++浠g爜闈欐佸垎鏋愬伐鍏?Prefast http://www.shnenglu.com/sandy/archive/2006/03/28/4689.html灝忔槑 灝忔槑 Tue, 28 Mar 2006 05:59:00 GMT http://www.shnenglu.com/sandy/archive/2006/03/28/4689.html http://www.shnenglu.com/sandy/comments/4689.html http://www.shnenglu.com/sandy/archive/2006/03/28/4689.html#Feedback 7 http://www.shnenglu.com/sandy/comments/commentRss/4689.html http://www.shnenglu.com/sandy/services/trackbacks/4689.html
1. 浠涔堟槸Prefast
Prefast鏄竴縐嶄唬鐮佸垎鏋愬伐鍏鳳紝瀹冭兘澶熷府鍔╀綘鎵懼埌緙栬瘧鍣ㄤ笉鑳芥壘鍒扮殑閿欒鎴栬呯己闄楓侾refast棣栨琚井杞泦鎴愬埌Visual Studio 2005 Team Suite涓幓錛屼嬌鐢ㄨ搗鏉ラ潪甯告柟渚褲?br />2.鎬庝箞浣跨敤Prefast 鍦╲s2005 Team Suite涓紝浣跨敤Prefast闈炲父綆鍗曘備慨鏀逛綘鐨勫伐紼嬪睘鎬э紝璁劇疆Enable Code Analysis For C/C++涓篩es. 鏁堟灉: 娉ㄦ剰鍒版湁鍙兘閿欒鐨勫湴鏂逛互嫻呯伆鑹叉樉紺哄湪緙栬緫鍣ㄤ腑浜嗐?/p>
3.Prefast鑳藉府浣犳壘鍒板摢浜涢敊璇?br />
1)娌℃湁鍒濆鍖?/p>
//
no聽initial
void
聽defect1() { 聽聽聽聽聽聽聽聽
int
聽a; 聽聽聽聽聽聽聽聽
int
聽b; 聽聽聽聽聽聽聽聽b聽
=
聽a; }
浼氭姤: d:\test\testcode\testcode.cpp(18) : warning C6001: Using uninitialized memory 'a': Lines: 15, 16, 18 2)絀烘寚閽堝彇鍊?br />
//
one聽path聽dereference聽NULL
void
聽defect4(
int
聽b,聽
int
聽c) { 聽聽聽聽聽聽聽聽
int
聽
*
p聽
=
聽NULL; 聽聽聽聽聽聽聽聽
int
聽a聽
=
聽
1
; 聽聽聽聽聽聽聽聽
if
聽(b聽
==
聽
1
)聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
if
聽(c聽
==
聽
1
)聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽p聽
=
聽
&
a; 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
else
聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
else
聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
if
聽(c聽
==
聽
1
)聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
else
聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽p聽
=
聽
&
a; 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
*
p; 聽聽聽聽聽聽聽聽
return
; }聽聽聽聽
浼氭姤:d:\test\testcode\testcode.cpp(65) : warning C6011: Dereferencing NULL pointer 'p': Lines: 45, 46, 48, 57, 65 3)鍙兘閿欒鐨勮繍綆楃浼樺厛綰?br />
void
聽defect5() { 聽聽聽聽聽聽聽聽
int
聽a聽
=
聽
1
; 聽聽聽聽聽聽聽聽
int
聽b聽
=
聽
1
; 聽聽聽聽聽聽聽聽
int
聽c聽
=
聽
1
; 聽聽聽聽聽聽聽聽
if
聽(a聽
&
聽b聽
==
聽c) 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return
; }
浼氭姤: d:\test\testcode\testcode.cpp(76) : warning C6281: Incorrect order of operations: relational operators have higher precedence than bitwise operators 4)鍙兘鐨刡uffer overrun
void
聽defect8() { 聽聽聽聽聽聽聽聽
char
聽buf[
100
]; 聽聽聽聽聽聽聽聽
char
聽buf2[
200
]; 聽聽聽聽聽聽聽聽
int
聽i聽
=
聽
100
; 聽聽聽聽聽聽聽聽sprintf(buf,聽
"
hello聽world聽%d
"
,聽i); 聽聽聽聽聽聽聽聽strcpy(buf,聽buf2); }
浼氭姤: d:\test\testcode\testcode.cpp(133) : warning C6202: Buffer overrun for 'buf', which is possibly stack allocated, in call to 'strcpy': length '200' exceeds buffer size '100' 5)鍙兘鐨勬棤絀峰驚鐜?br />
//
infinite聽loop
void
聽defect14() { 聽聽聽聽聽聽聽聽signed聽
char
聽i; 聽聽聽聽聽聽聽聽
for
聽(i聽
=
聽
100
;聽i聽
>=
聽
0
;聽i
++
)聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽;聽 聽聽聽聽聽聽聽聽} }
浼氭姤: d:\test\testcode\testcode.cpp(198) : warning C6292: Ill-defined for-loop: counts up from maximum 6)鏍煎紡瀛楃涓查敊璇?br />
//
Format聽string聽mismatch
void
聽defect21() { 聽聽聽聽聽聽聽聽
char
聽buff[
5
]; 聽聽聽聽聽聽聽聽sprintf(buff,聽
"
%s聽%s
"
,聽
"
a
"
); }
浼氭姤: d:\test\testcode\testcode.cpp(277) : warning C6063: Missing string argument to 'sprintf' that corresponds to conversion specifier '2' 7)瀹夊叏闂
void
聽defect27() { 聽聽聽聽聽聽聽聽CreateProcess(NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
"
c:\\program聽files\\Project.exe聽arg1
"
,聽
//
correct聽"\"c:\\program聽files\\Project.exe\"聽arg1",
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
false
, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
0
, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL, 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NULL);聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
浼氭姤: d:\test\testcode\testcode.cpp(327) : warning C6277: NULL application name with an unquoted path in call to 'CreateProcessA': results in a security vulnerability if the path contains spaces 8)=鍜?=璇敤
void
聽defect32() { 聽聽聽聽聽聽聽聽
int
聽a聽
=
聽
1
; 聽聽聽聽聽聽聽聽
if
聽(a聽
=
聽
2
) 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return
; }
浼氭姤: d:\test\testcode\testcode.cpp(405) : warning C6282: Incorrect operator: assignment of constant in Boolean context. Consider using '==' instead 9)閫昏緫榪愮畻闂
//
always聽false
void
聽defect45() { 聽聽聽聽聽聽聽聽
int
聽x; 聽聽聽聽聽聽聽聽
if
聽(
0
聽
&&
聽x
++
)聽{ 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽; 聽聽聽聽聽聽聽聽} }
浼氭姤: d:\test\testcode\testcode.cpp(564) : warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects 10)鍏朵粬
]]> C++璺ㄥ鉤鍙板紑鍙戞柟娉?宸ュ叿 http://www.shnenglu.com/sandy/archive/2006/03/24/4544.html灝忔槑 灝忔槑 Fri, 24 Mar 2006 08:45:00 GMT http://www.shnenglu.com/sandy/archive/2006/03/24/4544.html http://www.shnenglu.com/sandy/comments/4544.html http://www.shnenglu.com/sandy/archive/2006/03/24/4544.html#Feedback 26 http://www.shnenglu.com/sandy/comments/commentRss/4544.html http://www.shnenglu.com/sandy/services/trackbacks/4544.html 闃呰鍏ㄦ枃 ]]> 鍐嶈皥浠巚c6榪佺Щ鍒皏s2005 http://www.shnenglu.com/sandy/archive/2006/03/13/4081.html灝忔槑 灝忔槑 Mon, 13 Mar 2006 03:03:00 GMT http://www.shnenglu.com/sandy/archive/2006/03/13/4081.html http://www.shnenglu.com/sandy/comments/4081.html http://www.shnenglu.com/sandy/archive/2006/03/13/4081.html#Feedback 12 http://www.shnenglu.com/sandy/comments/commentRss/4081.html http://www.shnenglu.com/sandy/services/trackbacks/4081.html
浣滀負C++緙栬瘧鍣紝浠巚c6鍒皏c8鏈澶х殑璋冩暣灝辨槸瀵笴++鏍囧噯鐨勬敮鎸佹洿濂戒簡銆?BR> 鎴戝彂鐜扮殑鍑犵偣涓嶅悓銆?BR> a. For 寰幆鐨勫0鏄?BR> Vc6: for(int i<0;i<100;++i){}; j = i; (ok)
Vc8: for(int i<0;i<100;++i){}; j = i; (illegal)
int i; for(i<0;i<100;++i){}; j = i; (ok)
Vc8涓殑for寰幆涓彉閲忕殑鏈夋晥鏈熶粎浠呭湪for 寰幆鐨勫紑濮嬩笌緇撴潫鏈熼棿鏈夋晥銆?BR> b.string瀹炵幇
Vc6: string s; char *p = s.begin(); (ok)
Vc8: string s; char *p = s.begin(); (illegal)
string s; char *p = const_cast<char *>(s.c_str()); (ok)
鍦╲c6涓?string::iterator琚畾涔変負char *,浣嗘槸vc8涓笉鏄?BR> c.鏇翠弗鏍肩殑typename澹版槑鐨勯渶瑕?BR>
Vc6:
template<class T>
class Test
{
public:
typedef map<T,T> mymap;
mymap::iterator mymap_iter;
}; (ok)
Vc8:
template<class T>
class Test
{
public:
typedef map<T,T> mymap;
mymap::iterator mymap_iter;
}; (illegal)
typename mymap::iterator mymap_iter;(ok)
vc8鏇村姞涓ユ牸鐨勮姹傜▼搴忓憳鍦ㄧ被鍨嬪墠闈㈠姞涓妕ypename浠ラ伩鍏嶆涔?BR> d.涓嶅厑璁擱粯璁ょ殑int綾誨瀷
Vc6: fun() { return 0;} (ok)
Vc8: fun() { return 0;} (illegal)
int fun() { return 0;} (ok)
vc8涓嶆敮鎸侀粯璁よ繑鍥瀒nt綾誨瀷 e.typedef蹇呴』鏄痯ublic鎵嶈兘琚鐣岃闂埌
Vc6:
Class Test
{
typedef int iterator;
};
Test::iterator i; (ok)
Vc8:
Class Test
{
typedef int iterator;
};
Test::iterator i; (illegal)
Class Test
{
public:
typedef int iterator;
};
Test::iterator i; (ok)
闄勫綍錛氫竴浜涜祫婧愶紙From msdn)Overviews:
Moving from 6.0 to 7.1:
Moving from 7.1 to 8.0:
]]> Java涓渶鍊煎緱C++鍊熼壌鐨勭壒鎬 http://www.shnenglu.com/sandy/archive/2006/01/25/3018.html灝忔槑 灝忔槑 Wed, 25 Jan 2006 03:40:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/25/3018.html http://www.shnenglu.com/sandy/comments/3018.html http://www.shnenglu.com/sandy/archive/2006/01/25/3018.html#Feedback 16 http://www.shnenglu.com/sandy/comments/commentRss/3018.html http://www.shnenglu.com/sandy/services/trackbacks/3018.html 闃呰鍏ㄦ枃 ]]> 浠庡叏灞鍙橀噺鍒癐OC妯″紡 http://www.shnenglu.com/sandy/archive/2006/01/20/2941.html灝忔槑 灝忔槑 Fri, 20 Jan 2006 09:23:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/20/2941.html http://www.shnenglu.com/sandy/comments/2941.html http://www.shnenglu.com/sandy/archive/2006/01/20/2941.html#Feedback 7 http://www.shnenglu.com/sandy/comments/commentRss/2941.html http://www.shnenglu.com/sandy/services/trackbacks/2941.html 涓轟粈涔堣鍏ㄥ眬鍙橀噺? List 1
int main() { int s1,s2,s3; fun1(s1); fun2(s1,s2); fun3(s1,s2,s3); return 0 ; }
涓婇潰鐨剆1,s2,s3濡傛灉鏀規垚鍏ㄥ眬鍙橀噺錛屽垯鍙樹負 List 2
int s1,s2,s3; int main() { fun1(); fun2(); fun3(); }
浼間箮綆媧佷簡涓浜涳紝鑰屼笖娌℃湁浜嗕紶閫掑弬鏁扮殑寮閿銆備絾鏄己鐐逛篃鏄緢鏄庢樉鐨勶紝甯︿簡涓変釜鍑芥暟涔嬮棿鐨勮﹀悎銆?BR> 鏃㈢劧鎴戜滑璁よ瘑鍒板叏灞鍙橀噺鐨勯棶棰橈紝鎬庝箞鏀硅繘鍛紵 浠g爜1涓敱浜庢湁涓変釜鍙橀噺錛屽鏋滄湁鏇村鐨勶紝灝辨洿楹葷儲錛屾垜浠彲浠ヨ繖鏍鋒敼榪?BR>List 3
typedef struct statusTag { int s1,s2,s3; }Status; int main() { Status s; fun1( & s); fun2( & s); fun3( & s); return 0 ; }
榪欑鎶宸т綘鍙互鍦╨ua涓湅鍒幫紝鐪媗ua鐨勪嬌鐢ㄤ唬鐮?BR>List4
#include " lua.h " #include " lauxlib.h " #include " lualib.h " int main( int argc, char * argv[]) { lua_State * L = lua_open(); const char * buf = " var = 100 " ; int var ; luaopen_base(L); luaopen_io(L); lua_dostring(L, buf); lua_getglobal(L, " var " ); var = lua_tonumber(L, - 1 ); lua_close(L); return 0 ; }
璇鋒敞鎰忓埌榪欓噷鐨刲ua_open鏂規硶錛岃繖鍏跺疄鏄竴縐嶅垱寤鴻嚜宸辯殑宸ュ巶鏂規硶銆備笉浣跨敤鍏ㄥ眬鍙橀噺鐨勫ソ澶勫氨鏄紝鎴戜滑淇濈暀浜嗗彲浠ュ垱寤哄涓璞$殑鑷敱銆?BR> 鏃朵唬鍦ㄥ彂灞曪紝榪涘叆C++鏃朵唬錛屼絾鏄叏灞鍙橀噺浠嶇劧鏈変漢鍦ㄧ敤錛屽瓨鍦ㄥ氨鏄悎鐞嗙殑銆侴OF鎻愬嚭涓縐嶈璁℃ā寮忓彨Singleton鐨勬ā寮忥紝鍏舵牳蹇冩濇兂灝辨槸涓嶈鍏ㄥ眬鍙橀噺婕傛誕鍦ㄧ┖涓紝鎶婂畠鏀懼叆class涓紝鎴愪負琛e啝妤氭鐨凜++鍏皯銆傝憲鍚嶇殑Meyer Singleton鍍忚繖鏍?BR>List 5
class Status { private : Status(){}; public : static Status & getInstance() { static Status s; return s; } }; class User { void fun() { Status & s = Status::Instance(); // . . .use s } };
涓鍒囦技涔庡緢瀹岀編錛屼嬌鐢╬rivate鏉ラ槻姝lient 鍒涘緩瀹冿紝淇濊瘉浜嗗璞$殑鍞竴鎬?娉ㄦ剰:Meyer singleton騫朵笉鍏鋒湁澶氱嚎紼嬪畨鍏紝鍙兘瀵艱嚧澶氭鍒濆鍖栧璞? 浣嗘槸闅忕潃 閽堝鎺ュ彛緙栫▼鍜屽崟鍏冩祴璇曡秺鏉ヨ秺嫻佽錛宻ingleton甯︽潵鐨勫鍗曞厓嫻嬭瘯涓嶅弸濂界殑鐗圭偣鏃ョ泭浣撶幇錛屽叏灞鍙橀噺涓嶈兘寰堝ソ鐨勮mock錛屾墍浠ラ毦浜庢祴璇曘?BR> 榪欐椂鍊欐墍璋撶殑IOC鎬濇兂(Inversion of Control錛屽嵆鍙嶈漿妯″紡) 鍑烘潵浜嗭紝綆鍗曠殑鏉ヨ錛屽氨鏄氳繃鏋勯犲嚱鏁版垨鑰卻et鏂規硶瀹炵幇娉ㄥ叆 List6 - 鏋勯犲嚱鏁版敞鍏?BR>
class Status{}; class User { public : User(Status * s):m_ps(s){}; void fun() { Status * s = m_ps; } private : Status * m_ps; }
List7 - Set 娉ㄥ叆
class Status{}; class User { public : User(){} void setStaus(Status * s) { m_ps = s; } void fun() { Status * s = m_ps; } private : Status * m_ps; }
浣跨敤IOC鐨勫ソ澶勬槸甯︽潵浜嗘洿寮哄ぇ鐨勭伒媧繪э紝浣嗘槸甯︽潵鐨勯棶棰樺氨鏄皟鐢ㄨ呴夯鐑︿簡(澶╀笅娌℃湁鍏嶈垂鐨勫崍槨愰樋錛?BR> List8
int main() { Status s; User u; u.setStatus( & s); u.fun(); return 0 ; }
濂藉儚涓鍒囧張榪旀湸褰掔湡錛屼技涔庡茍娌℃湁甯︽潵浠涔堢畝鍗曘傛湁鐨勬椂鍊欑畝鍗曞拰鐏墊椿鎬у氨鏄瀵瑰ご銆?BR> 涓轟簡綆鍖栫敤鎴瘋繘琛屾墜宸ユ敞鍏ワ紝IOC瀹瑰櫒鍑虹幇錛屽湪Java涓栫晫閲岄潰錛屾渶钁楀悕鐨勮帿榪囦簬Spring浜?IOC瀹瑰櫒灝卞儚涓涓法澶х殑鍒涘緩宸ュ巶錛屽ス鍙互浣跨敤xml鏉ラ厤緗繖浜涳紝榪欑湡鐨勬槸涓鍦洪潻鍛姐?BR>
< beans > < bean id = " status " class = " Status " > </ bean > < bean id = " user " class = " User " > < property name = " status " >< ref bean = " status " /></ property > </ bean > </ beans >
Spring灝辨槸榪欐牱鎶婃敞鍏ョ殑宸ヤ綔縐誨埌閰嶇疆鏂囦歡涓幓錛屾彁渚涗簡寮哄ぇ鐨勭伒媧繪у拰鍙厤緗?BR> 浣嗘槸鐢變簬c/c++ 涓嶅叿澶囩殑java閭d箞澶氳繍琛屾湡鐨勭被鍨嬭瘑鍒拰鍙嶅皠鐨勫姛鑳斤紝鎵浠ユ垜鐩墠榪樻病鏈夊彂鐜版湁鍦–++涓嬌鐢ㄧ殑IOC瀹瑰櫒錛屽鏋滀綘鐭ラ亾錛岃鍛婅瘔鎴?BR> 閭d箞濡傛灉鏄疌++鎬庝箞鏉ヤ嬌娉ㄥ叆鍙樺緱綆鍗曚竴鐐瑰憿錛屽彲浠ヤ嬌鐢ㄥ伐鍘傛柟娉曚簡 List9
User * createUser(Status & s,Status2 & s2) { User * user = new User(); user -> setStatus(s); user -> setStatus2(s2); return user; }
鎬葷粨: 鍏跺疄杞歡鐨勮璁℃牴鏈氨娌℃湁鎵璋撶殑榛勯噾娉曞垯錛屾病鏈夊厤璐圭殑鍗堥錛屼綘鍦ㄨ幏寰楁洿寮哄ぇ鐨勭伒媧繪э紝寰寰閮藉緱鍒板鏉傛х殑闄勫姞鏁堟灉銆傚鏋滀綘灝辨槸鍐欎竴涓嚜宸辯帺鐨勫皬娓告垙錛宱k,浣犲氨鏄敤鍏ㄥ眬鍙橀噺銆傚鏋滀綘瑕佽璁″簽澶х殑Office,閭d綘灝辨病鏈夊姙娉曟妸浠g爜鍐欑殑寰堢畝鍗曪紝鍥犱負浣犺鑰冭檻鐨勪笢瑗垮浜嗭紝鍙淮鎶ゆэ紝鍙祴璇曟с?img src ="http://www.shnenglu.com/sandy/aggbug/2941.html" width = "1" height = "1" /> ]]>C++緙栬瘧鏈烠onstraints璁捐 http://www.shnenglu.com/sandy/archive/2006/01/17/2830.html灝忔槑 灝忔槑 Tue, 17 Jan 2006 06:12:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/17/2830.html http://www.shnenglu.com/sandy/comments/2830.html http://www.shnenglu.com/sandy/archive/2006/01/17/2830.html#Feedback 0 http://www.shnenglu.com/sandy/comments/commentRss/2830.html http://www.shnenglu.com/sandy/services/trackbacks/2830.html 甯哥敤鐨勮鍒? 1.澶у皬涓?鐨勬暟緇勫湪緙栬瘧鏈熶細鎶ラ敊
template < typename T1,typename T2 > void check_size() { int dmp[ sizeof (T1) == sizeof (T2)]; }
姣斿 check_size<int,long>();//ok check_size<int,char>();//compile error:cannot allocate an array of constant size 02.涓嶅悓綾誨瀷鐨勬寚閽堥渶瑕佸己鍒惰漿鎹?/STRONG> 浠ユ鍙互鐢ㄦ潵鍒ゆ柇涓や釜瀵硅薄鏄惁鏈夌戶鎵垮叧緋?BR>
template < typename T1,typename T2 > void is_derived(T1 * pd =0 ,T2 * pb=0) { pb = pd; }
姣斿: is_derived<int,char>() //compile failed3.union鐨勬垚鍛樹笉鑳芥槸闈濸OD union Test { std::string s; //illegal }; 榪欎竴鐐瑰彲浠ョ敤鏉ユ祴璇曚竴涓被鍨嬫槸鍚︽槸POD
template < typename T > void check_pod() { union { T data; }; };
姣斿: check_pod<int>();//ok check_pod<std::string>();//failed 甯哥敤鐨勬妧宸?1.鍒╃敤妯℃澘鐗瑰寲 Loki閲岄潰鐨勪緥瀛?BR>
namespace Loki { template < int > struct CompileTimeError; template <> struct CompileTimeError < true > {}; } #define LOKI_STATIC_CHECK(expr, msg) \ { Loki::CompileTimeError< ((expr) != 0 ) > ERROR_##msg; ( void )ERROR_##msg; }
鍒╃敤鐗瑰寲鏉ュ畾鍒墮敊璇俊鎭?BR> 2.鍒╃敤絀哄嚱鏁版潵瀹炵幇0寮閿 緙栬瘧鍣ㄥ彲鑳藉皢絀哄嚱鏁頒紭鍖栨帀 3.鍒╃敤enum鏃犲紑閿鐨勫彇寰楃紪璇戞湡鐨勬墍寰楀埌鐨勬暣鏁板?BR> Loki閲岄潰鐨勪緥瀛?
template < class TList > struct Length; template <> struct Length < NullType > { enum { value = 0 }; }; template < class T, class U > struct Length < Typelist < T, U > > { enum { value = 1 + Length < U > ::value }; };
]]> 浠涔堟墠鏄綰跨▼瀹夊叏鐨?/title> http://www.shnenglu.com/sandy/archive/2006/01/12/2690.html灝忔槑 灝忔槑 Thu, 12 Jan 2006 09:45:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/12/2690.html http://www.shnenglu.com/sandy/comments/2690.html http://www.shnenglu.com/sandy/archive/2006/01/12/2690.html#Feedback 19 http://www.shnenglu.com/sandy/comments/commentRss/2690.html http://www.shnenglu.com/sandy/services/trackbacks/2690.html 鎵浠ュ涔犲綰跨▼緙栫▼鏈閲嶈鐨勪笉鏄涔燗PI,鑰屾槸鐞嗚В浠涔堟墠鏄綰跨▼瀹夊叏鐨勪唬鐮?BR> 浠庝緥瀛愯璧?BR>
#include < windows.h > #include < process.h > long global1 = 0 ; volatile long global2 = 0 ; class MyClass { public : MyClass() : m( 0 ) { ++ m; } int fun( int v) { return m + v; // -----------9 } void set ( int v) { m = v; // -------------10 } int m; }; MyClass global_object; // -------------8 unsigned int __stdcall thread_fun1( void * param) { static int static2 = 0 ; static MyClass static_object; // --------6 int local1 = 0 ; ++ local1; // -------1 ++ static2; // -------2 ++ global1; // -------3 ++ global2; // -------4 InterlockedIncrement( & global1); // --------5 local1 = global_object.fun(local1); // ----------7 global_object.set (local1); // ---------------11 return 0 ; } unsigned int __stdcall thread_fun2( void * param) { ++ global1; // -------3 ++ global2; // -------4 InterlockedIncrement( & global1); // --------5 global_object.set ( 1 ); // -----------11 return 0 ; } int main() { HANDLE thread1 = (HANDLE)_beginthreadex( 0 , 0 , & thread_fun1, 0 , 0 , 0 ); // thread 1 HANDLE thread2 = (HANDLE)_beginthreadex( 0 , 0 , & thread_fun1, 0 , 0 , 0 ); // thread 2 HANDLE thread3 = (HANDLE)_beginthreadex( 0 , 0 , & thread_fun2, 0 , 0 , 0 ); // thread 3 WaitForSingleObject(thread1,INFINITE); WaitForSingleObject(thread2,INFINITE); WaitForSingleObject(thread3,INFINITE); return 0 ; }
1.灞閮ㄥ彉閲忓眬閮ㄤ嬌鐢ㄦ槸瀹夊叏鐨?/STRONG> 涓轟粈涔?鍥犱負姣忎釜thread 閮芥湁鑷繁鐨勮繍琛屽爢鏍堬紝鑰屽眬閮ㄥ彉閲忔槸鐢熷瓨鍦ㄥ爢鏍堜腑,澶у涓嶅共鎵般?BR>鎵浠ヤ唬鐮? int local1; ++local1; 鏄畨鍏ㄧ殑2.鍏ㄥ眬鍘熺敓鍙橀噺澶氱嚎紼嬭鍐欐槸涓嶅畨鍏ㄧ殑 鍏ㄥ眬鍙橀噺鏄湪鍫?heap)涓?BR>long global1 = 0; ++global2; ++榪欎釜鎿嶄綔鍏跺疄鍒嗕負涓ら儴錛屼竴涓槸璇伙紝鍙﹀涓涓槸鍐?BR> mov ecx,global add ecx,1 mov global,ecx 鎵浠ヤ唬鐮?澶勬槸涓嶅畨鍏ㄧ殑3.鍑芥暟闈欐佸彉閲忓綰跨▼璇誨啓涔熸槸涓嶅畨鍏ㄧ殑 閬撶悊鍚? 鎵浠ヤ唬鐮?澶勪篃鏄笉瀹夊叏鐨?BR>4.volatile鑳戒繚璇佸叏灞鏁村艦鍙橀噺鏄綰跨▼瀹夊叏鐨勪箞 涓嶈兘銆?BR>volatile浠呬粎鏄憡璇玞ompiler涓嶈瀵硅繖涓彉閲忎綔浼樺寲錛屾瘡嬈¢兘瑕佷粠memory鍙栨暟鍊鹼紝鑰屼笉鏄粠register 鎵浠ヤ唬鐮?涔熶笉鏄畨鍏?BR>5.InterlockedIncrement淇濊瘉鏁村瀷鍙橀噺鑷鐨勫師瀛愭?/STRONG> 鎵浠ヤ唬鐮?鏄畨鍏ㄧ殑6.function static object鐨勫垵濮嬪寲鏄綰跨▼瀹夊叏鐨勪箞 涓嶆槸銆?BR>钁楀悕鐨凪eyer Singleton鍏跺疄涓嶆槸綰跨▼瀹夊叏鐨?BR>Object & getInstance() { static Object o; return o; } 鍙兘浼氶犳垚澶氭鍒濆鍖栧璞?BR>鎵浠ヤ唬鐮?澶勬槸涓嶅畨鍏ㄧ殑7.鍦?2鏈哄櫒涓婏紝4瀛楄妭鏁村艦涓嬈ssign鏄師瀛愮殑 姣斿 i =10; //thread1 i=4; //thread2 涓嶄細瀵艱嚧i鐨勫煎浜庢湭鐭ョ姸鎬?瑕佷箞鏄?0瑕佷箞鏄? 鍏跺畠鐨勫ぇ瀹惰嚜宸卞幓浣撲細銆?BR> 鍐欏ソ澶氱嚎紼嬪畨鍏ㄧ殑娉曞疂灝辨槸灝佽錛屼嬌鏁版嵁鏈変繚鎶ょ殑琚闂埌 瀹夊叏鎬э細 灞閮ㄥ彉閲?gt;鎴愬憳鍙橀噺>鍏ㄥ眬鍙橀噺 ]]> 璇″紓鐨凜 http://www.shnenglu.com/sandy/archive/2006/01/09/2504.html灝忔槑 灝忔槑 Mon, 09 Jan 2006 06:04:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/09/2504.html http://www.shnenglu.com/sandy/comments/2504.html http://www.shnenglu.com/sandy/archive/2006/01/09/2504.html#Feedback 12 http://www.shnenglu.com/sandy/comments/commentRss/2504.html http://www.shnenglu.com/sandy/services/trackbacks/2504.html 1.鏃犵┓loop
int i,a[ 10 ]; for (i = 0 ;i <= 10 ; ++ i) { a[i] = 0 ; }
why? 鍑芥暟榪愯鏃跺爢鏍堬細 a[0] a[1] ....a[9] i a[10] = 0;鏀瑰彉i鐨勫間負0,閫犳垚鏃犵┓寰幆
2.鍏繘鍒剁殑璇敤
int i[] = { 012 , 024 , 125 , };
涓轟簡瀵歸綈鍙兘閫犳垚鐨勯敊璇紝鍙樻垚浜嗗叓榪涘埗
3.濡備綍璋冪敤鍦板潃涓?鐨勮繃紼嬶紵 (*(void(*)())0)(); ps:鍦ㄥぇ澶氭暟鐜頒唬鎿嶄綔緋葷粺錛岃繘紼嬪紩鐢ㄧ殑鍦板潃涓鴻櫄鎷熷湴鍧錛屾墍浠ヨ繖涓皟鐢ㄥ彲鑳藉悎娉?/P>
4.榪愮畻絎︾殑浼樺厛綰?/STRONG>
int i = 1 ; i = i << 4 + 2 ;
榪欐椂i鐨勫兼槸澶氬皯錛?BR>涓嶆槸18錛屾槸64錛屽洜涓?i=i<<4+2; <==> i=i<<(4+2);
5.鎮寕鐨刬f
if (x == 0 ) // 1 if (y == 0 ) error(); // 2 else { // 3 z = x + y; f( & z); }
C涓殑else鎬繪槸鍜屾渶榪戠殑if鍖歸厤錛屾墍浠?鍜?鍖歸厤錛岃屼笉鏄拰1鍖歸厤銆傜瓑浠蜂簬
if (x == 0 ) // 1 { if (y == 0 ) error(); // 2 else { // 3 z = x + y; f( & z); } }
瑙e喅鏂規硶錛氭繪槸浣跨敤{}鍜宨f閰嶅
]]>C++鎬ц兘浼樺寲瀹炶返2---閫夋嫨鍚堥傜殑瀹瑰櫒 http://www.shnenglu.com/sandy/archive/2006/01/05/2448.html灝忔槑 灝忔槑 Thu, 05 Jan 2006 05:07:00 GMT http://www.shnenglu.com/sandy/archive/2006/01/05/2448.html http://www.shnenglu.com/sandy/comments/2448.html http://www.shnenglu.com/sandy/archive/2006/01/05/2448.html#Feedback 1 http://www.shnenglu.com/sandy/comments/commentRss/2448.html http://www.shnenglu.com/sandy/services/trackbacks/2448.html 涓嬮潰鐨勪竴涓緥瀛愶紝鏄粡甯稿湪欏圭洰涓兘浼氱敤鍒扮殑.ini閰嶇疆鏂囦歡鐢熸垚鍜岃В鏋愮殑榪囩▼ 姣斿 [section1] key1 = value1 ;here is comment key2 = value2 [section2] key3 = value3 key4 = value4 褰撶劧WinAPI涔熸彁渚涗簡WritePrivateProfileString ,GetPrivateProfileString 涓や釜API鏉ヨ鍐欒繖縐嶆枃浠舵牸寮忥紝浣嗘槸 姣忔浣跨敤閮戒細鎵撳紑鏂囦歡鏉ヨ鍐欙紝鎬ц兘闈炲父浣庯紝鍙傜敤浜庡皬瑙勬ā鐨勬暟鎹鍐欍?BR> 鐪嬫垜浠殑浠g爜錛?BR>
#define _TD_INI_H_ #include < list > #include < fstream > using namespace std; class KEV_VALUE { public : KEV_VALUE(){m_bIsGarbage = FALSE;m_bSingleLine = FALSE;}; virtual ~ KEV_VALUE(){}; string m_key; string m_value; BOOL m_bIsGarbage; BOOL m_bSingleLine; }; typedef list < KEV_VALUE > LIST_KEY_VELUE; class SECTION { public : SECTION(){}; virtual ~ SECTION(){}; string m_section; LIST_KEY_VELUE m_listKeyValue; }; typedef list < SECTION > LIST_SECTION; class CTDIni { public : CTDIni( void ); virtual ~ CTDIni( void ); BOOL UpdateData( BOOL bSave = true ); void SetFileName( const CHAR * lpstrFileName ); BOOL GetLastSectionName( string & str ); BOOL AddSection( const CHAR * lpstrSection ); BOOL DeleteSection( const CHAR * lpstrSection); BOOL ReadSection( const CHAR * lpszSection, string & str ); BOOL SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const CHAR * lpstrValue ); BOOL SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const INT32 nValue ); BOOL GetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, CHAR * lpstrValue ); BOOL DeleteKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey ); BOOL ChangeKeyName( const CHAR * lpstrSection, const CHAR * lpstrKeyOld, const CHAR * lpstrKeyNew ); BOOL ChangeSectionName( const CHAR * lpstrSectionOld, const CHAR * lpstrSectionNew ); private : LIST_SECTION m_sections; string m_strFileName; BOOL AddGarbage( const CHAR * lpstrSection, const CHAR * lpstrGarbage, BOOL bSingleLine = FALSE ); }; #endif // !defined(_TD_INI_H_)
榪欎釜鏄В鏋愮被鐨勫0鏄庯紝閲嶈鐨勬槸瀹冪殑鏁版嵁緇撴瀯錛屽畠閲囩敤浜嗕袱綰ч摼琛ㄧ殑緇撴瀯錛岀涓綰ф槸鎵鏈塻ection鐨刲ist,絎簩綰ф槸section涓嬮潰鐨刱ey-value鐨刲ist. 涓嬮潰鏄叾涓殑瀹炵幇浠g爜鐗囨柇
BOOL CTDIni::SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const CHAR * lpstrValue ) { LIST_SECTION::iterator i; for ( i = m_sections.begin(); i != m_sections.end(); i ++ ) { if ( ( * i).m_section == lpstrSection ) { LIST_KEY_VELUE::iterator j; for ( j = ( * i).m_listKeyValue.begin(); j != ( * i).m_listKeyValue.end(); j ++ ) { if ( ( * j).m_key == lpstrKey ) { ( * j).m_value = lpstrValue; return TRUE; } } KEV_VALUE tmp; tmp.m_key = lpstrKey; tmp.m_value = lpstrValue; ( * i).m_listKeyValue.push_back( tmp ); return TRUE; } } return FALSE; }
涓婇潰鐨勪竴涓柟娉曟槸娣誨姞涓涓煎埌閰嶇疆涓幓錛屽畠鐨勭畻娉曟槸棣栧厛鏌ユ壘瀹冩墍鍦ㄧ殑section,鐒跺悗鏌ユ壘鎵鍦ㄧ殑key, 鏈鍚庡喅瀹氭槸insert榪樻槸update. 榪欐牱鎬ц兘闂灝辨潵浜嗭紝褰撴暟鎹笉鏂鍔狅紝SetKeyValue鎵闇瑕佺殑鏃墮棿鍛圢*N鐨勬柟寮忓闀褲傚緢鍙曘侰PU鐨勫崰鐢ㄧ巼涔熶細璺戝埌寰堥珮銆?BR> 鏈鍚庯紝鎴戜滑涓嶅緱涓嶈繘琛屼紭鍖栵紝鍥犱負鍦ㄦ垜浠殑欏圭洰涓紝涓嶅瓨鍦ㄧ浉鍚岀殑section錛屼篃娌℃湁鐩稿悓鐨刱ey,鎵浠ユ垜浠嬌鐢╩ap錛屼嬌寰楁煡鎵炬椂闂村彉鎴愬父鏁扮駭鍒?鍗充嬌鏈夌浉鍚岀殑key§ion,涔熷彲浠ヤ嬌鐢╩ultimap) 浼樺寲鍚庣殑鏁版嵁緇撴瀯鏄繖鏍風殑
#include < string > #include < stdio.h > #include < list > #include < map > #include < fstream > using namespace std; struct VELUE { string m_value; BOOL m_bIsGarbage; BOOL m_bSingleLine; }; typedef std::map < std:: string ,VELUE > MAP_KEY_VELUE; typedef std::map < std:: string ,MAP_KEY_VELUE > MAP_SECTION; class CTDIni { public : CTDIni( void ); virtual ~ CTDIni( void ); BOOL UpdateData( BOOL bSave = true ); void SetFileName( const CHAR * lpstrFileName ); BOOL GetLastSectionName( string & str ); BOOL AddSection( const CHAR * lpstrSection ); BOOL DeleteSection( const CHAR * lpstrSection); BOOL ReadSection( const CHAR * lpszSection, string & str ); BOOL IsExistSection( const CHAR * lpstrSection); BOOL SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const CHAR * lpstrValue ); BOOL SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const INT32 nValue ); BOOL GetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, CHAR * lpstrValue ); BOOL DeleteKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey ); BOOL ChangeKeyName( const CHAR * lpstrSection, const CHAR * lpstrKeyOld, const CHAR * lpstrKeyNew ); BOOL ChangeSectionName( const CHAR * lpstrSectionOld, const CHAR * lpstrSectionNew ); private : MAP_SECTION m_sections; string m_strFileName; BOOL AddGarbage( const CHAR * lpstrSection, const CHAR * lpstrGarbage, BOOL bSingleLine = FALSE ); };
SetKeyValue閭d釜鏂規硶鐨勫疄鐜版槸榪欐牱錛?BR>
BOOL CTDIni::SetKeyValue( const CHAR * lpstrSection, const CHAR * lpstrKey, const CHAR * lpstrValue ) { MAP_SECTION::iterator i; MAP_KEY_VELUE::iterator j; i = m_sections.find(lpstrSection); if ( i == m_sections.end()) { return FALSE; } j = i -> second.find(lpstrKey); if ( j != i -> second.end()) // update { j -> second.m_value = lpstrValue; } else // insert { VELUE tmp; tmp.m_value = lpstrValue; tmp.m_bSingleLine = false ; tmp.m_bIsGarbage = false ; i -> second[lpstrKey] = tmp; } return TRUE; }
涓よ呯殑鎬ц兘宸窛鏈夊澶э紵瓚呰繃浣犵殑鎯寵薄 ]]>鍒╃敤boost::serialization鏉ュ疄鐜癈++ RMI http://www.shnenglu.com/sandy/archive/2005/12/29/2236.html灝忔槑 灝忔槑 Thu, 29 Dec 2005 06:42:00 GMT http://www.shnenglu.com/sandy/archive/2005/12/29/2236.html http://www.shnenglu.com/sandy/comments/2236.html http://www.shnenglu.com/sandy/archive/2005/12/29/2236.html#Feedback 5 http://www.shnenglu.com/sandy/comments/commentRss/2236.html http://www.shnenglu.com/sandy/services/trackbacks/2236.html 鍏堟潵涓猙oost::serlization浣跨敤鐨勪緥瀛?BR>
#include < boost / archive / text_oarchive.hpp > #include < boost / archive / text_iarchive.hpp > #include < boost / archive / xml_oarchive.hpp > void test_serialization() { boost::archive::text_oarchive to(cout , boost::archive::no_header); int i = 10 ; string s = " This is a test\n " ; to & i; to & s; ofstream f( " test.xml " ); boost::archive::xml_oarchive xo(f); xo & BOOST_SERIALIZATION_NVP(i) & BOOST_SERIALIZATION_NVP(s); boost::archive::text_iarchive ti(cin , boost::archive::no_header); ti & i & s; cout << " i= " << i << endl; cout << " s= " << s << endl; }
鍋囧鎴戜滑鍙互灝唎bject搴忓垪鍖栦互鍚庨氳繃socket浼犺繃鍘伙紝灝卞彲浠ュ疄鐜癛MI浜嗐?BR>褰撶劧榪欑鏂規硶鍙兘鏄湪C++紼嬪簭涔嬮棿浼犻掋?BR> 浠婂ぉ鍦╟odeproject涓婇潰鍙戠幇宸茬粡鏈変漢宸茬粡榪欐牱鍋氫簡錛屽師鏉ユ棭灝辨湁浜鴻窡鎴戞湁涓鏍風殑鎯蟲硶 鐪嬬湅浣滆呭皝瑁呯殑緇撴灉鍚?BR> server绔?
#include < RCF / RCF.hpp > RCF_BEGIN(I_Echo, " I_Echo " ) RCF_METHOD_R1(std:: string , echo, const std:: string & ); RCF_END(I_Echo); class Echo { public : std:: string echo( const std:: string & msg) { return msg; } }; int main() { int port = 50001 ; RCF::RcfServer server(port); server.bind < I_Echo, Echo > (); server.start(); return 0 ; }
client绔細
#include < RCF / RCF.hpp > RCF_BEGIN(I_Echo, " I_Echo " ) RCF_METHOD_R1(std:: string , echo, const std:: string & ); RCF_END(I_Echo); int main() { std::cout << RcfClient < I_Echo > ( " localhost " , 50001 ).echo( " my message " ); return 0 ; }
姣旇緝綆媧?鍒╃敤浜哹oost寮哄ぇ鐨刦unction,thread,serlization RCF涓嬭澆鍦板潃: http://www.codeproject.com/threads/RMI_For_Cpp/RCF.zip 浠嬬粛錛?http://www.codeproject.com/threads/RMI_For_Cpp.asp ]]>C++鎬ц兘浼樺寲瀹炶返1---璁捐鏁版嵁緇撴瀯 http://www.shnenglu.com/sandy/archive/2005/12/22/1973.html灝忔槑 灝忔槑 Thu, 22 Dec 2005 12:42:00 GMT http://www.shnenglu.com/sandy/archive/2005/12/22/1973.html http://www.shnenglu.com/sandy/comments/1973.html http://www.shnenglu.com/sandy/archive/2005/12/22/1973.html#Feedback 8 http://www.shnenglu.com/sandy/comments/commentRss/1973.html http://www.shnenglu.com/sandy/services/trackbacks/1973.html 瀵逛簬鎬ц兘浼樺寲錛岀浉淇″枩嬈++鐨勪漢閮芥槸姣旇緝閲嶈鏁堢巼銆傛垜鍑嗗鍐欎竴涓郴鍒楋紝涓昏鏄熀浜庢垜鐨勪竴浜涘疄璺碉紝鑷充簬鐞嗚涓婄殑涓滆タ錛屼笉鏄垜鐨勯噸鐐廣傛垜涔熻涓嶅嚭鏉ヤ竴鍫嗛亾鐞?-)銆傛垜鎵璇寸殑渚嬪瓙錛岄兘灝嗘槸鎴戜互鍓嶆墍閬囧埌鐨勪竴浜涙渚嬶紝璁板綍涓涓嬫濊礬錛屾嬁鍑烘潵璺熷ぇ瀹秙hare銆?BR> 鍦–++紼嬪簭涓紝鑷粠鏈変簡STL,寰堝皯鏈変漢鍘昏嚜宸卞幓璁捐鏁版嵁緇撴瀯錛屽綋鐒跺ぇ閮ㄥ垎鎯呭喌STL鐨勬晥鐜囬兘鏄彲浠ョ殑銆備竾浜嬮兘鏈変緥澶栥?BR> 鎴戞帴瑙﹀埌涓涓渶姹傦紝鏄牴鎹墜鏈哄彿鐮佺殑鍙鋒琛?浣嶆暟涓嶅畾錛屼竴鑸槸涓冨叓浣嶏級鏉ユ煡鍑烘墜鏈哄彿鐮佹墍鍦ㄧ殑鍦板尯銆?BR>姣斿 1315156 鍗椾含 13812345 鍖椾含 1366789 涓婃搗 025 鍗椾含 涓縐嶅彲鑳界殑鏂規鏄璁″涓猦ashmap map<int,string> seg8; map<int,string> seg7; map<int,string> seg3; ... 姣忎釜map鍒嗗埆瀵瑰簲涓嶅悓鐨勪綅鏁般傚浜庝竴涓猵hone,鍒嗗埆鍦ㄨ繖浜沵ap涓煡鎵?BR>浣嗘槸鏁堢巼涓嶈銆?BR> 榪欓噷闈㈡湁涓叧閿紝鍥犱負鎵嬫満鍙風爜閮芥槸鏁板瓧錛屾垜浠彲浠ヨ璁″嚭涓媯墊爲錛屾瘡涓妭鐐歸兘鏄?-9錛屼粬鍙互鏈?0涓妭鐐癸紝鍙跺瓙鑺傜偣鎴戜滑灝卞彲浠ュ偍瀛樻暟鎹傝繀閫熷湪澶ц剳閲屾兂璞′竴涓繖鏍風殑妯″瀷銆?BR> 榪樻槸鐪嬩唬鐮佹瘮杈冩槑浜嗐?鍗佸弶鏍?/STRONG>
#if !defined __TREE10__ #define __TREE10__ #pragma warning(disable:4786 ) namespace sandy { namespace Private { template < class VALUE > struct __Node10 // 鑺傜偣struct { typedef __Node10 < VALUE >* POINTER; VALUE * data; // 鏁版嵁 POINTER ptr[ 10 ]; // 瀛愯妭鐐?/SPAN> __Node10():data( 0 ) { memset(ptr, 0 , sizeof (POINTER) * 10 ); } }; } template < typename VALUE > class CTree10 { typedef Private::__Node10 < VALUE > NODE; private : long m_lcount; // 鎻掑叆鐨勬暟鎹暟閲?/SPAN> long m_lnodecount; // 鑺傜偣鏁?/SPAN> NODE * m_proot; // 鏍圭粨鐐規寚閽?/SPAN> public : CTree10():m_lcount( 0 ),m_lnodecount( 0 ),m_proot(CreateNode()) // notice:Keep order with their declare { } ~ CTree10() { DestroyAll(); } void DestroyAll() { for ( short i = 0 ;i < 10 ; ++ i) { if (m_proot -> ptr[i] != 0 ) { Remove(m_proot -> ptr[i]); m_proot -> ptr[i] = 0 ; } } } bool Insert( const char * pKey, const VALUE & data) // 鎻掑叆鑺傜偣 { assert(pKey != 0 ); NODE * pNode = m_proot; NODE * pChildNode = 0 ; char c = 0 ; for (unsigned int i = 0 ;i < strlen(pKey); ++ i) { c = pKey[i]; if (c < ' 0 ' || c > ' 9 ' ) return false ; pChildNode = pNode -> ptr[(c - ' 0 ' )]; if (pChildNode == 0 ) // not build { pChildNode = pNode -> ptr[(c - ' 0 ' )] = CreateNode(); // create a new child } pNode = pChildNode ; // change node to child node } if (pNode -> data == 0 ) // empty { pNode -> data = new VALUE(data); ++ m_lcount; return true ; } else // already inserted { return false ; } } bool Lookup( const char * pKey,VALUE & data, bool strick = true ) { assert(pKey != 0 ); NODE * pNode = m_proot; NODE * pChildNode = 0 ; char c = 0 ; for (unsigned int i = 0 ;i < strlen(pKey); ++ i) { c = pKey[i]; if (c < ' 0 ' || c > ' 9 ' ) return false ; pChildNode = pNode -> ptr[(c - ' 0 ' )]; if (pChildNode != 0 ) { pNode = pChildNode; } else // can't find { if ( ! strick) { break ; } return false ; } } if (pNode -> data != 0 ) // already inserted { data = * (pNode -> data); return true ; } else // no inserted { return false ; } } private : NODE * CreateNode() { NODE * pNewNode = new NODE(); assert(pNewNode != 0 ); ++ m_lnodecount; return pNewNode; } void Remove(NODE * pNode) { assert(pNode != 0 ); for ( short i = 0 ; i < 10 ; i ++ ) { if ( pNode -> ptr[ i ] ) Remove( pNode -> ptr[ i ] ); } if (pNode -> data != 0 ) { delete pNode -> data; -- m_lcount; } -- m_lnodecount; delete pNode; } }; } #endif
榪欎釜Tree10鎴戝湪vc6涓嬫祴璇曠殑緇撴灉錛?BR>鎻掑叆閫熷害姣攕td::map蹇?鍊嶏紝鏌ヨ閫熷害鍒欐槸std::map鐨?0鍊?BR>
]]> vc6鍑芥暟璋冪敤嫻呮瀽 http://www.shnenglu.com/sandy/archive/2005/12/14/1745.html灝忔槑 灝忔槑 Wed, 14 Dec 2005 08:53:00 GMT http://www.shnenglu.com/sandy/archive/2005/12/14/1745.html http://www.shnenglu.com/sandy/comments/1745.html http://www.shnenglu.com/sandy/archive/2005/12/14/1745.html#Feedback 5 http://www.shnenglu.com/sandy/comments/commentRss/1745.html http://www.shnenglu.com/sandy/services/trackbacks/1745.html 鎴戝啓涓嬩簡濡備笅浠g爜錛?BR>
int fun( int a, int b) { int i = 3 ; return a + b + i; } int main() { int a = 1 ,b = 2 ; int result ; result = fun( 1 , 2 ); return result; }
闈炲父綆鍗曘傚弽姹囩紪鍚?Debug鐗?鍙樻垚榪欐牱
1 : int fun( int a, int b) 2 : { 00401020 push ebp 00401021 mov ebp,esp 00401023 sub esp,44h 00401026 push ebx 00401027 push esi 00401028 push edi 00401029 lea edi,[ebp - 44h] 0040102C mov ecx,11h 00401031 mov eax,0CCCCCCCCh 00401036 rep stos dword ptr [edi] 3 : int i = 3 ; 00401038 mov dword ptr [ebp - 4 ], 3 4 : return a + b + i; 0040103F mov eax,dword ptr [ebp + 8 ] 00401042 add eax,dword ptr [ebp + 0Ch] 00401045 add eax,dword ptr [ebp - 4 ] 5 : } 00401048 pop edi 00401049 pop esi 0040104A pop ebx 0040104B mov esp,ebp 0040104D pop ebp 0040104E ret 7 : int main() 8 : { 00401060 push ebp 00401061 mov ebp,esp 00401063 sub esp,4Ch 00401066 push ebx 00401067 push esi 00401068 push edi 00401069 lea edi,[ebp - 4Ch] 0040106C mov ecx,13h 00401071 mov eax,0CCCCCCCCh 00401076 rep stos dword ptr [edi] 9 : int a = 1 ,b = 2 ; 00401078 mov dword ptr [ebp - 4 ], 1 0040107F mov dword ptr [ebp- 8 ], 2 10 : int result ; 11 : result = fun( 1 , 2 ); 00401086 push 2 00401088 push 1 0040108A call @ILT+ 5 (fun) (0040100a) 0040108F add esp, 8 00401092 mov dword ptr [ebp - 0Ch],eax 12 : return result; 00401095 mov eax,dword ptr [ebp - 0Ch] 13 : } 00401098 pop edi 00401099 pop esi 0040109A pop ebx 0040109B add esp,4Ch 0040109E cmp ebp,esp 004010A0 call __chkesp (004010c0) 004010A5 mov esp,ebp 004010A7 pop ebp 004010A8 ret
鎴戜滑涓昏鏉ョ湅鐪嬪嚱鏁拌皟鐢ㄩ儴鍒?BR>1.鍙傛暟鍘嬫爤 push 2 push 1 鍙傛暟浠庡彸鍚戝乏鍘嬫爤(__cdcel),esp閫掑噺2.璋冪敤鍑芥暟 call @ILT+5(fun) (0040100a) 榪欐潯鎸囦護浼氭妸涓嬩竴琛屼唬鐮佺殑鍦板潃鍘嬫爤錛屼篃灝辨槸鍑芥暟榪斿洖鍦板潃銆傚悓鏃惰煩杞埌鍑芥暟鍏ュ彛澶?BR>3.榪涘叆鍑芥暟浣?/STRONG> push ebp mov ebp,esp 棣栧厛淇濆瓨ebp鐨勫湴鍧錛岀劧鍚庢妸esp淇濆瓨鍒癳bp涓幓 00401023 sub esp,44h 00401026 push ebx 00401027 push esi 00401028 push edi 鍑忓皬stack鐨勬寚閽?娉ㄦ剰錛宻tack鏄粠鍐呭瓨鐨勯珮绔悜浣庣鐢熼暱鐨?錛屼負灞閮ㄥ彉閲忎繚鐣欎竴浜涚┖闂達紝榪欓噷鐨?4h涓嶆槸鍥哄畾鐨勶紝鐢辯紪璇戝櫒璁$畻寰楁潵 00401029 lea edi,[ebp-44h] 0040102C mov ecx,11h 00401031 mov eax,0CCCCCCCCh 00401036 rep stos dword ptr [edi] 鐢?xCC濉厖灞閮ㄥ彉閲忕┖闂淬傝繖鏄疍ebug妯″紡鐗規湁鐨勶紝濡傛灉鏄瓧絎︿覆錛屼綘灝辯湅鍒拌鍒濆鍖栨垚"鐑儷鐑儷鐑儷" 鑷蟲錛屾暣涓爢鏍堝彉鎴?BR>|-----------------| | 灞閮ㄥ彉閲? | |-----------------| | 灞閮ㄥ彉閲? |<----ebp-4 |-----------------| | old ebp |<----ebp |-----------------| | 鍑芥暟榪斿洖鍦板潃| <----ebp+4 |-----------------| | 鍙傛暟1 | <----ebp+8 |-----------------| | 鍙傛暟2 | |-----------------| Next: int i = 3; 00401038 mov dword ptr [ebp-4],3 榪欓噷浣犵湅鍒癧ebp-4]灝辨槸絎竴涓眬閮ㄥ彉閲廼浜?BR>0040103F mov eax,dword ptr [ebp+8] 00401042 add eax,dword ptr [ebp+0Ch] 00401045 add eax,dword ptr [ebp-4] [ebp+8],[ebp+0Ch]鍒嗗埆鏄痑鍜宐浜?BR>4.鍑芥暟榪斿洖 鍑芥暟鐨勭粨鏋滈兘鏄斁鍦╡ax涓?ps:浣犲彲浠ュ湪vc鐨剋atch紿楀彛杈撳叆@EAX錛屽氨鍙互鐩存帴鐪嬪埌鍑芥暟榪斿洖鍊間簡錛?BR>00401048 pop edi 00401049 pop esi 0040104A pop ebx 0040104B mov esp,ebp 0040104D pop ebp 0040104E ret 鎶奺di,esi,ebx鎭㈠錛岀劧鍚庢仮澶峞sp,ebp,榪欐椂鍑芥暟鐨勮繑鍥炲湴鍧灝卞湪鏍堥《錛岃皟鐢╮et灝卞彲浠ヨ繑鍥炰簡銆?BR> 閭e鏋滄敼鍙樺嚱鏁扮殑榪斿洖鍦板潃浼氭庢牱錛?BR>ok,鎴戜滑淇敼涓涓嬩唬鐮侊細
#include < stdio.h > void fun2() { printf( " fun2() called " ); } int fun( int a, int b) { int i = 3 ; printf( " return address:0x%x\n " , & i + 2 ); printf( " fun2 address:0x%x\n " , & fun2); /* int *p = (int*)&fun2; __asm { mov ebx,p mov dword ptr[ebp+4],ebx } */ * ( & i + 2 ) = ( int ) & fun2; // modify return address return a + b + i; } int main() { int a = 1 ,b = 2 ; int result ; result = fun( 1 , 2 ); return result; }
Wow,榪欐椂錛屾垜浠氨浼氬彂鐜癴un2琚皟鐢ㄤ簡銆傝繖灝辨槸Buffer overrun(緙撳啿婧㈠嚭)鎵鍋氱殑浜嬫儏鍚с?BR>5.鏈鍚庝竴姝ワ紝璋冪敤鑰呰皟鏁村爢鏍堟寚閽?/STRONG> call @ILT+5(fun) (0040100a) add esp,8 涓轟粈涔堣璋冩暣鍛紝鍥犱負璋冪敤涔嬪墠push涓や釜鍙傛暟榪涘叆鏍堬紝鐜板湪瑕佹仮澶嶅畠 mov dword ptr [ebp-0Ch],eax 榪欏彞璇濆氨鏄韓鐢ㄥ嚱鏁拌皟鐢ㄧ殑鏋滃疄浜?EAX淇濆瓨浜嗗嚱鏁扮殑榪斿洖鍊? ------end-------- ]]> 鑰冭冧綘瀵笴++瀵硅薄妯″瀷鐨勭悊瑙?/title> http://www.shnenglu.com/sandy/archive/2005/12/06/1557.html灝忔槑 灝忔槑 Tue, 06 Dec 2005 01:34:00 GMT http://www.shnenglu.com/sandy/archive/2005/12/06/1557.html http://www.shnenglu.com/sandy/comments/1557.html http://www.shnenglu.com/sandy/archive/2005/12/06/1557.html#Feedback 12 http://www.shnenglu.com/sandy/comments/commentRss/1557.html http://www.shnenglu.com/sandy/services/trackbacks/1557.html 1.璇峰湪涓嶈繍琛岀▼搴忕殑鎯呭喌涓嬶紝璇村嚭涓嬮潰鐨勭▼搴忚繍琛屽悗浼氬穿婧冧箞錛熷鏋滄槸錛屽湪鍝竴琛屻?BR>
1 #include < stdio.h > 2 #include < memory.h > 3 class Test 4 { 5 public : 6 Test() 7 { 8 memset( this , 0 , sizeof ( * this )); 9 } 10 int s; 11 void test() 12 { 13 printf( " test()\n " ); 14 } 15 void test1() 16 { 17 printf( " test1():%d\n " , this -> s); 18 } 19 virtual void test2() 20 { 21 printf( " test2()\n " ); 22 } 23 }; 24 25 int main() 26 { 27 Test * s; 28 s -> test(); 29 s -> test2(); 30 s -> test1(); 31 return 0 ; 32 }
2 .淇敼涓涓嬶紝鍙堟槸鍦ㄥ摢涓琛屽憿錛?BR>
1 #include < stdio.h > 2 #include < memory.h > 3 class Test 4 { 5 public : 6 Test() 7 { 8 memset( this , 0 , sizeof ( * this )); 9 } 10 int s; 11 void test() 12 { 13 printf( " test()\n " ); 14 } 15 void test1() 16 { 17 printf( " test1():%d\n " , this -> s); 18 } 19 virtual void test2() 20 { 21 printf( " test2()\n " ); 22 } 23 }; 24 25 int main() 26 { 27 Test * s = new Test(); 28 s -> test(); 29 s -> test1(); 30 s -> test2(); 31 return 0 ; 32 }
3.鍐嶄慨鏀逛竴涓嬶紝鎯呭喌浼氬浣曞憿錛?BR>
1 #include < stdio.h > 2 #include < memory.h > 3 class Test 4 { 5 public : 6 Test() 7 { 8 memset( this , 0 , sizeof ( * this )); 9 } 10 int s; 11 void test() 12 { 13 printf( " test()\n " ); 14 } 15 void test1() 16 { 17 printf( " test1():%d\n " , this -> s); 18 } 19 virtual void test2() 20 { 21 printf( " test2()\n " ); 22 } 23 }; 24 25 int main() 26 { 27 Test s ; 28 s.test(); 29 s.test1(); 30 s.test2(); 31 return 0 ; 32 }
鏈鍚庤涓涓嬬瓟妗堝惂 絎竴棰樻槸鍦?9琛岋紝絎簩棰樺湪30琛岋紝鏈鍚庝竴棰樹笉鎶ラ敊銆?BR>濡傛灉浣犱笉鐭ラ亾涓轟粈涔堬紝寤鴻鐪嬬湅<<Inside the c++ Object Model>>
]]> Just for fun:鑳借緭鍑鴻嚜韜唬鐮佺殑紼嬪簭 http://www.shnenglu.com/sandy/archive/2005/12/02/1483.html灝忔槑 灝忔槑 Fri, 02 Dec 2005 02:58:00 GMT http://www.shnenglu.com/sandy/archive/2005/12/02/1483.html http://www.shnenglu.com/sandy/comments/1483.html http://www.shnenglu.com/sandy/archive/2005/12/02/1483.html#Feedback 21 http://www.shnenglu.com/sandy/comments/commentRss/1483.html http://www.shnenglu.com/sandy/services/trackbacks/1483.html 鏉′歡錛氫笉鍊熷姪浠諱綍鏂囦歡鎿嶄綔錛岃緭鍑虹▼搴忕殑source code . 紼嬪簭錛?BR>
#include < stdio.h > char c[] = { 0x7d , 0x3b , 0xa , 0x69 , 0x6e , 0x74 , 0x20 , 0x6d , 0x61 , 0x69 , 0x6e , 0x28 , 0x29 , 0xa , 0x7b , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x70 , 0x72 , 0x69 , 0x6e , 0x74 , 0x66 , 0x28 , 0x22 , 0x23 , 0x69 , 0x6e , 0x63 , 0x6c , 0x75 , 0x64 , 0x65 , 0x20 , 0x3c , 0x73 , 0x74 , 0x64 , 0x69 , 0x6f , 0x2e , 0x68 , 0x3e , 0x5c , 0x6e , 0x63 , 0x68 , 0x61 , 0x72 , 0x20 , 0x63 , 0x5b , 0x5d , 0x20 , 0x3d , 0x20 , 0x7b , 0x22 , 0x29 , 0x3b , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x66 , 0x6f , 0x72 , 0x28 , 0x69 , 0x6e , 0x74 , 0x20 , 0x69 , 0x3d , 0x30 , 0x3b , 0x69 , 0x3c , 0x73 , 0x69 , 0x7a , 0x65 , 0x6f , 0x66 , 0x28 , 0x63 , 0x29 , 0x3b , 0x2b , 0x2b , 0x69 , 0x29 , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x7b , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x70 , 0x72 , 0x69 , 0x6e , 0x74 , 0x66 , 0x28 , 0x22 , 0x30 , 0x78 , 0x25 , 0x78 , 0x2c , 0x22 , 0x2c , 0x63 , 0x5b , 0x69 , 0x5d , 0x29 , 0x3b , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x7d , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x70 , 0x72 , 0x69 , 0x6e , 0x74 , 0x66 , 0x28 , 0x22 , 0x25 , 0x73 , 0x22 , 0x2c , 0x63 , 0x29 , 0x3b , 0xa , 0x20 , 0x20 , 0x20 , 0x20 , 0x72 , 0x65 , 0x74 , 0x75 , 0x72 , 0x6e , 0x20 , 0x30 , 0x3b , 0xa , 0x7d ,}; int main() { printf( " #include <stdio.h>\nchar c[] = { " ); for ( int i = 0 ;i < sizeof (c); ++ i) { printf( " 0x%x, " ,c[i]); } printf( " %s " ,c); return 0 ; }
鑷充簬鎬庝箞鍋氬埌鐨勶紝澶у鍙互鑷繁鐞㈢( 涓嶈繃涓嶈浠ヤ負鍙湁C鑳藉仛鍒幫紝java涔熷彲浠ュ摝 ]]>
7国产欧美日韩综合天堂中文久久久久 |
人人妻久久人人澡人人爽人人精品
|
亚洲女久久久噜噜噜熟女 |
亚洲国产一成久久精品国产成人综合
|
日产精品久久久一区二区 |
精品国产乱码久久久久久1区2区
|
久久久国产精品福利免费 |
日本一区精品久久久久影院 |
亚洲国产精品成人久久 |
中文精品久久久久人妻不卡 |
成人午夜精品久久久久久久小说 |
亚洲国产精品嫩草影院久久 |
青青久久精品国产免费看 |
久久精品国产亚洲AV无码麻豆 |
精品国产91久久久久久久a |
欧美精品一区二区久久 |
伊人久久大香线蕉综合5g |
久久人妻少妇嫩草AV无码蜜桃 |
日本精品久久久久中文字幕 |
久久综合亚洲欧美成人 |
久久国产美女免费观看精品 |
亚洲精品乱码久久久久久蜜桃图片
|
精品久久久久久亚洲 |
亚洲精品tv久久久久久久久久 |
久久露脸国产精品 |
亚洲国产精品无码久久SM |
久久精品夜夜夜夜夜久久 |
青青草国产精品久久 |
一极黄色视频久久网站 |
久久精品a亚洲国产v高清不卡 |
国产成人综合久久精品尤物 |
久久久高清免费视频 |
精品免费久久久久国产一区 |
亚洲国产成人精品91久久久
|
热re99久久精品国99热 |
久久久青草久久久青草 |
亚洲一区精品伊人久久伊人 |
国产亚洲精品自在久久 |
亚洲中文字幕伊人久久无码 |
国内精品伊人久久久久AV影院 |
久久激情五月丁香伊人 |