| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> jing hua :C++ bian cheng xin shou cuo wu yu lu ( xu yi )

jing hua :C++ bian cheng xin shou cuo wu yu lu ( xu yi )

2008-06-01 02:04:54 编辑來源:互联网 评论
 
 
 
本文为【精华:C++编程新手错误语录(续一)】的拼音翻译版
  fei hua bu shuo , zhi jie jin ru zheng ti , ben wen cheng jie xian qian fa bu de 《C/C++ bian cheng xin shou cuo wu yu lu 》(http://www.pconline.com.cn/pcedu/empolder/gj/c/0508/691597.Html), ji xu gui na cuo wu yu lu 。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  (8)“ wo xiang yong malloc”、“ wo yong bu hao malloc”
  lai kan kan yi ge bian tai cheng xu :
  /* xx.c:xx mo kuai shi xian wen jian */
  int *pInt;
  /* xx mo kuai de chu shi hua han shu */
  xx_intial()
  {
  pInt = ( int * ) malloc ( sizeof( int ) );
  ...
  }
  /* xx mo kuai de qi ta han shu ( jin wei ju li )*/
  xx_otherFunction()
  {
  *Int = 10;
  ...
  }
  zhe ge cheng xu ding yi le yi ge quan ju zheng xing bian liang zhi zhen , zai xx mo kuai de chu shi hua han shu zhong dui ci zhi zhen dong tai shen qing nei cun , bing jiang pInt zhi xiang gai nei cun shou di zhi , bing zai xx mo kuai de qi ta han shu zhong dou shi yong pInt zhi zhen dui qi zhi xiang de zheng shu jin xing du qu he fu zhi 。
  zhe ge cheng xu rang wo tong bu yu sheng le hao duo tian , e wan tan xi ! zhe shi wo mu xiao ji suan ji xi yi wei shuo shi de zuo pin ! zuo zhe wei le yong shang malloc, pin ming di ba ben lai ying gai yong yi ge quan ju zheng xing bian liang bai ping de cheng xu huo huo nong cheng yi ge quan ju zheng xing zhi zhen bing zai chu shi hua han shu zhong “ dong tai ” shen qing nei cun , zi zuo cong ming er zheng hao bao lu zi ji de wu zhi ! wo zai ye bu yao jian dao zhe yang de cheng xu 。
  na me malloc jiu jing ying gai zen me yong ? bi zhe gei chu ru xia gui ze :
  gui ze 1 bu yao wei le yong malloc er yong malloc,malloc bu shi mu de , er shi shou duan ;
  gui ze 2malloc de zhen zheng nei han ti xian zai “ dong tai ” shen qing , jia ru cheng xu de te xing bu xu dong tai shen qing , qing bu yao yong malloc;
  shang mian lie ju de bian tai cheng xu wan quan bu ju bei xu yao dong tai shen qing de te zhi , ying gai gai wei :
  /* xx.c:xx mo kuai shi xian wen jian */
  int example;
  /* xx mo kuai de chu shi hua han shu */
  xx_intial()
  {
  ...
  }
  /* xx mo kuai de qi ta han shu ( jin wei ju li ) */
  xx_otherFunction()
  {
  example = 10;
  ...
  }
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti java bian cheng kai fa shou ce zhuan ti , huo
  gui ze 3 shen me yang de cheng xu ju bei xu yao dong tai shen qing nei cun de te zhi ne ? bao han liang zhong qing kuang :
  (1) bu zhi dao you duo shao yao lai , lai le de you zou le
  bu ming bai ? zhe me shuo ba , pi ru ni zheng zai chu li yi ge bao wen dui lie , shou dao de bao wen ni dou cun ru gai dui lie , chu li wan dui lie tou de bao wen hou ni xu yao qu chu dui lie tou de yuan su 。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  ni bu zhi dao you duo shao bao wen lai ( yin er ni bu zhi dao ying gai yong duo da de bao wen shu zu ), zhe xie lai de bao wen chu li wan hou dou yao zou ( shi fang ), zhe zhong qing kuang shi he yong malloc he free。
  (2) man man di chang da
  pi ru ni zai zi yuan shou xian de xi tong zhong bian xie yi wen ben bian ji qi cheng xu , ni zen me zuo , ni xu yao zhe yang ding yi shu zu ma ?
  char str[10000]; bu , ni wan quan bu ying gai zhe me zuo 。 ji shi ni ding yi le yi ge 10000 zi jie da de zi fu chuan , yong hu jia ru shu ru 10001 ge zi fu ni de cheng xu jiu wan wan le 。
  zhe ge shi hou shi he yong malloc, yin wei ni gen ben jiu bu zhi dao yong hu hui shu ru duo shao zi fu , wen ben zai man man chang da , yin er ni ye ying man man di shen qing nei cun , yong yi ge dui lie ba zi fu chuan cun fang qi lai 。
  na me shi bu shi ying gai zhe yang ding yi shu ju jie gou bing zai yong hu mei shu ru yi ge zi fu de qing kuang xia malloc yi ge CharQueue kong jian ne ?
  typedef strUCt tagCharQueue
  
   {
  char ch;
  struct tagCharQueue *next;
  }CharQueue;
  bu , zhe yang zuo ye bu dui ! zhe jiang shi mei ge zi fu zhan ju “1+ zhi zhen chang du ” de kai xiao 。
  zheng que de zuo fa shi :
  typedef struct tagCharQueue
  {
  char str[100];
  struct tagCharQueue *next;
  }CharQueue;
  rang zi fu yi 100 wei dan wei man man di zou , dang shu ru zi fu shu da dao 100 de zheng shu bei shi , shen qing yi pian CharQueue kong jian 。
  
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
  gui ze 4malloc yu free yao cheng dui chu xian
  ta men shi yi dui en ai fu qi ,malloc shao le free jiu bi ran hui man man di si diao 。 cheng dui chu xian bu jin ti xian zai you duo shao ge malloc jiu ying gai you duo shao ge free, huan ti xian zai ta men ying jin liang chu xian zai tong yi han shu li ,“ shui shen qing , jiu you shui shi fang ”, kan xia mian de cheng xu :
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  char * func(void)
  {
  char *p;
  p = (char *)malloc(…);
  if(p!=NULL)
  …; /* yi xi lie zhen dui p de cao zuo */
  return p;
  }
  /* zai mou chu tiao yong func(), yong wan func zhong dong tai shen qing de nei cun hou jiang qi free*/
  char *q = func();
  …
  free(q);
  shang shu dai ma wei fan le malloc he free de “ shui shen qing , jiu you shui shi fang ” yuan ze , dai ma de ou he du da , yong hu zai tiao yong func han shu shi xu que qie zhi dao qi nei bu xi jie ! zheng que de zuo fa shi :
  /* zai tiao yong chu shen qing nei cun , bing chuan ru func han shu */
  char *p=malloc(…);
  if(p!=NULL)
  {
  func(p);
  …
  free(p);
  p=NULL;
  }
  /* han shu func ze jie shou shen shu p */
  void func(char *p)
  {
  … /* yi xi lie zhen dui p de cao zuo */
  }
  gui ze 5free hou yi ding yao zhi zhi zhen wei NULL, fang zhi qi cheng wei “ ye ” zhi zhen
  (9)“ han shu add bian yi sheng cheng de fu hao jiu shi add”
  int add(int x,int y)
  {
  return x + y;
  }
  float add(float x,float y)
  {
  return x + y;
  }
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
  ji bian shi zai C yu yan zhong ,add han shu bei duo shu C bian yi qi bian yi hou zai fu hao ku zhong de ming zi ye bu shi add, er shi _add。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  er zai C++ bian yi qi zhong ,int add(int x,int y) hui bian yi cheng lei si _add_int_int zhe yang de ming zi ( cheng wei “mangled name”),float add(float x,float y) ze bei bian yi cheng _add_float _float,mangled name bao han le han shu ming 、 han shu shen shu shu liang ji lei xing xin xi ,C++ yi kao zhe zhong ji zhi lai shi xian han shu chong zai 。
  suo yi , zai C++ zhong , ben zhi shang int add( int x, int y ) yu float add( float x, float y ) shi liang ge wan quan bu tong de han shu , zhi shi zai yong hu kan lai qi tong ming er yi 。
  zhe jiu yao qiu chu xue zhe men neng tou guo yu fa xian xiang kan wen ti ben zhi 。 ben zhi shang , yu yan de chuang zao zhe men jiu shi zai wan ge zhong ge yang de hua yang , yi shi yu yan ju bei mou zhong neng li , pi ru mangled name hua yang de mu de zai yu shi C++ zhi chi chong zai 。 er C yu yan mei you wan zhe yang de hua yang , suo yi int add( int x, int y ) yu float add( float x, float y ) bu neng zai C cheng xu zhong tong shi cun zai 。
  (10)“ mei jian guo zai C yu yan zhong tiao yong C++ de han shu ”、“C/C++ bu neng tiao yong Basic、Pascal yu yan de han shu ”
  zhe you shi yi ge qi tian xia zhi da guai de wen ti ,“ da si wo dou bu xiang xin C、C++、basic、pascal de han shu neng xia tiao lai tiao qu ”, ke shi you ju hua zhe me shuo :
  mei you ni jian bu dao de , zhi you ni xiang bu dao de !
  ji ran fu rong jie jie ye you qi wen ming tian xia de dao li , na me C、C++、Basic、Pascal de han shu wei shen me jiu bu neng hu xiang tiao yong ne ?
  neng !
  ni ke yi yong Visual C++ xie yi ge DLL zai Visual Basic、Delphi(Pascal de sun zi ,Object Pascal de er zi ) zhong tiao yong , ye ke yi zai Visual Basic、Delphi zhong xie yi ge DLL zai Visual C++ zhong tiao yong bu shi ?
  
  
  rang wo men lai tou guo xian xiang kan ben zhi 。 shou xian kan kan han shu de tiao yong yue ding ( yi Visual C++ lai shuo ming ):
  (1) _stdcall tiao yong
  _stdcall shi Pascal cheng xu de que sheng tiao yong fang shi , shen shu cai yong cong you dao zuo de ya zhan fang shi , bei tiao han shu zi shen zai fan hui qian qing kong dui zhan 。
  WIN32 Api dou cai yong _stdcall tiao yong fang shi , zhe yang de hong ding yi shuo ming le wen ti :
  #define WINAPI _stdcall an C bian yi fang shi ,_stdcall tiao yong yue ding zai shu chu han shu ming qian mian jia xia hua xian , hou mian jia “@” fu hao he shen shu de zi jie shu , xing ru _functionname@number。
  
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
  (2) _cdecl tiao yong
  _cdecl shi C/C++ de que sheng tiao yong fang shi , shen shu cai yong cong you dao zuo de ya zhan fang shi , chuan song shen shu de nei cun zhan you tiao yong zhe wei hu 。_cedcl yue ding de han shu zhi neng bei C/C++ tiao yong , mei yi ge tiao yong ta de han shu dou bao han qing kong dui zhan de dai ma , suo yi chan sheng de ke zhi xing wen jian da xiao hui bi tiao yong _stdcall han shu de da 。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  you yu _cdecl tiao yong fang shi de shen shu nei cun zhan you tiao yong zhe wei hu , suo yi bian chang shen shu de han shu neng ( ye zhi neng ) shi yong zhe zhong tiao yong yue ding 。 guan yu C/C++ zhong bian chang shen shu (…) de wen ti , bi zhe jiang ling wen xiang shu 。
  you yu Visual C++ mo ren cai yong _cdecl tiao yong fang shi , suo yi VC zhong zhong tiao yong DLL shi , yong hu ying shi yong _stdcall tiao yong yue ding 。
  an C bian yi fang shi ,_cdecl tiao yong yue ding jin zai shu chu han shu ming qian mian jia xia hua xian , xing ru _functionname。
  (3) _fastcall tiao yong
  _fastcall tiao yong jiao kuai , ta tong guo CPU nei bu ji cun qi chuan di shen shu 。
  an C bian yi fang shi ,_fastcall tiao yong yue ding zai shu chu han shu ming qian mian jia “@” fu hao , hou mian jia “@” fu hao he shen shu de zi jie shu , xing ru @functionname@number。
  yao hai zi _stdcall、_cdecl he _fastcall ke yi zhi jie jia zai han shu qian , ye ke yi zai Visual C++ zhong she zhi , ru tu 1。
精华:C++编程新手错误语录(续一)
tu 1 zai VC zhong she zhi han shu tiao yong yue ding zai chuang jian DLL shi , yi ban shi yong _stdcall tiao yong (Win32 Api fang shi ), cai yong _functionname@number ming ming gui ze , yin er ge zhong yu yan jian de DLL neng hu xiang tiao yong 。 ye jiu shi shuo ,DLL de bian zhi yu ju ti de bian cheng yu yan ji bian yi qi wu guan , zhi yao zun shou DLL de kai fa gui fan he bian cheng ce lue , bing an pai zheng que de tiao yong jie kou , bu guan yong he zhong bian cheng yu yan bian zhi de DLL dou ju you tong yong xing 。
  tui er guang zhi , jia ru you zhe yang yi ge IDE kai fa huan jing , ta neng shi bie ge zhong yu yan , suo you yu yan cai yong xiang tong de tiao yong yue ding he ming ming gui ze , yi ge ruan jian nei ge zhong yu yan shu xie de han shu jiang neng hu xiang tiao yong !
  zhe ge shi jie shang ke neng yong yuan bu xu yao zhe yang yi ge IDE。
  (11)“ ying yu 、 shu xue bu hao jiu xue bu hao C/C++”
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
  zhe ye xu shi 20 shi ji zui da de huang yan , zhe ju hua zui xian shi na wei da shi de ming ren ming yan yi wu ke kao zheng , ke ci hou yi pi pi de ren bei ta wu dao 。 xu duo chu xue zhe yin wei zhe ju hua bei xia dao , fang qi le zuo cheng xu yuan de li xiang 。
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  huan you xu duo hou lai cheng wei you xiu cheng xu yuan de ren , zai ta men de cheng chang guo cheng zhong bing mei you yi kao shen ao de shu xue , ke ta men huan shi zai zong jie jing yan shi zhi zao kong huang , hao cheng yi ding yao ju bei gao shen de shu xue zhi shi , wei kong bie ren xiao hua qi xue shu shui ping bu gao 。
  zai xia ze ren wei , da duo shu qing kuang xia , cheng xu she ji bu xu yao tai shen ao de shu xue gong di , chu fei ni suo cong shi de cheng xu she ji she ji te ding de zhuan ye ling yu ( ru yu yin ji tu xiang chu li 、 shu zi tong xin ji shu deng )。 zai xia zhe yi guan dian ye xu shi ge jiu li xin , er ge ming bi ran yao liu xue xi sheng ( tan si tong ), suo yi gong hou da jia ban zhuan 。
  na me ying yu zai C/C++ de xue xi zhong chu yu shen me di wei ne ? na jiu shi neng kan dong zi liao , kan dong MSDN。
  xue bian cheng de zhong ji zhi dao bu zai kan shu , er zai da liang di bu duan di shi jian 。
  (12)“C++ tai nan le , wo xue bu hui ”
  
   you bu zhi shi shui de bei guan lun tiao , xu duo chu xue zhe bei C++ xia dao ,“ tai nan le , wo xue bu hao ”, ru ruo zhe zi lian 。 jia ru C++ zhen de nan dao xue bu hui , na me C++ de chuang zao zhe men suo cong shi de gong zuo qi bu shi “ fei ren li suo neng ji ye ”?
  zai xia ren wei , xue xi C++ de tai du ying gai shi : zhan lue shang miao shi ta , zhan shu shang chong shi ta , yao gan yu sheng li (《 mao zhu xi yu lu 》)。 dang ran ye bu ke qing di , bu neng yin wei ba wo le yi dian pi mao jiu yi wei zi ji niu B hong hong le ( bi zhe zeng jing niu B hong hong le hao yi zhen zi , xian zai xiang lai , shen jiao dang shi you zhi )。
  jia ru ni zheng fu le C++, tou che li jie le C++ de yu yan te xing ji STL, na me , qi ta yu yan xiang bu bei ni zheng fu dou nan le 。
  ben hui shu zhe luo ci chu , geng duo cuo wu yu lu , dang ran shi dai xu 。
精华:C++编程新手错误语录(续一)
geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   fei hua bu shuo , zhi jie jin ru zheng ti , ben wen cheng jie xian qian fa bu de 《C/C++ bian cheng xin shou cuo wu yu lu 》(http://www.pconline.com.cn/pcedu/empolder/gj/c/0508/691597.Html), ji xu gui na cuo wu yu lu 。 (8)“ wo xiang yong malloc”、“ wo yong bu hao malloc”    lai kan kan yi ge bian tai cheng xu : /* xx.c:xx mo kuai shi xian wen jian */ int *pInt; /* xx mo kuai de chu shi hua han shu */ xx_intial() { pInt = ( int * ) malloc ( sizeof( int ) ); ... } /* xx mo kuai de qi ta han shu ( jin wei ju li )*/ xx_otherFunction() { *Int = 10; ... }    zhe ge cheng xu ding yi le yi ge quan ju zheng xing bian liang zhi zhen , zai xx mo kuai de chu shi hua han shu zhong dui ci zhi zhen dong tai shen qing nei cun , bing jiang pInt zhi xiang gai nei cun shou di zhi , bing zai xx mo kuai de qi ta han shu zhong dou shi yong pInt zhi zhen dui qi zhi xiang de zheng shu jin xing du qu he fu zhi 。    zhe ge cheng xu rang wo tong bu yu sheng le hao duo tian , e wan tan xi ! zhe shi wo mu xiao ji suan ji xi yi wei shuo shi de zuo pin ! zuo zhe wei le yong shang malloc, pin ming di ba ben lai ying gai yong yi ge quan ju zheng xing bian liang bai ping de cheng xu huo huo nong cheng yi ge quan ju zheng xing zhi zhen bing zai chu shi hua han shu zhong “ dong tai ” shen qing nei cun , zi zuo cong ming er zheng hao bao lu zi ji de wu zhi ! wo zai ye bu yao jian dao zhe yang de cheng xu 。    na me malloc jiu jing ying gai zen me yong ? bi zhe gei chu ru xia gui ze :    gui ze 1  bu yao wei le yong malloc er yong malloc,malloc bu shi mu de , er shi shou duan ;    gui ze 2 malloc de zhen zheng nei han ti xian zai “ dong tai ” shen qing , jia ru cheng xu de te xing bu xu dong tai shen qing , qing bu yao yong malloc;    shang mian lie ju de bian tai cheng xu wan quan bu ju bei xu yao dong tai shen qing de te zhi , ying gai gai wei : /* xx.c:xx mo kuai shi xian wen jian */ int example; /* xx mo kuai de chu shi hua han shu */ xx_intial() { ... } /* xx mo kuai de qi ta han shu ( jin wei ju li ) */ xx_otherFunction() { example = 10; ... } [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867390.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti java bian cheng kai fa shou ce zhuan ti , huo    gui ze 3  shen me yang de cheng xu ju bei xu yao dong tai shen qing nei cun de te zhi ne ? bao han liang zhong qing kuang :   (1) bu zhi dao you duo shao yao lai , lai le de you zou le    bu ming bai ? zhe me shuo ba , pi ru ni zheng zai chu li yi ge bao wen dui lie , shou dao de bao wen ni dou cun ru gai dui lie , chu li wan dui lie tou de bao wen hou ni xu yao qu chu dui lie tou de yuan su 。    ni bu zhi dao you duo shao bao wen lai ( yin er ni bu zhi dao ying gai yong duo da de bao wen shu zu ), zhe xie lai de bao wen chu li wan hou dou yao zou ( shi fang ), zhe zhong qing kuang shi he yong malloc he free。   (2) man man di chang da    pi ru ni zai zi yuan shou xian de xi tong zhong bian xie yi wen ben bian ji qi cheng xu , ni zen me zuo , ni xu yao zhe yang ding yi shu zu ma ?   char str[10000];   bu , ni wan quan bu ying gai zhe me zuo 。 ji shi ni ding yi le yi ge 10000 zi jie da de zi fu chuan , yong hu jia ru shu ru 10001 ge zi fu ni de cheng xu jiu wan wan le 。    zhe ge shi hou shi he yong malloc, yin wei ni gen ben jiu bu zhi dao yong hu hui shu ru duo shao zi fu , wen ben zai man man chang da , yin er ni ye ying man man di shen qing nei cun , yong yi ge dui lie ba zi fu chuan cun fang qi lai 。    na me shi bu shi ying gai zhe yang ding yi shu ju jie gou bing zai yong hu mei shu ru yi ge zi fu de qing kuang xia malloc yi ge CharQueue kong jian ne ? typedef strUCt tagCharQueue { char ch; struct tagCharQueue *next; }CharQueue;    bu , zhe yang zuo ye bu dui ! zhe jiang shi mei ge zi fu zhan ju “1+ zhi zhen chang du ” de kai xiao 。    zheng que de zuo fa shi : typedef struct tagCharQueue { char str[100]; struct tagCharQueue *next; }CharQueue;    rang zi fu yi 100 wei dan wei man man di zou , dang shu ru zi fu shu da dao 100 de zheng shu bei shi , shen qing yi pian CharQueue kong jian 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867436.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo    gui ze 4 malloc yu free yao cheng dui chu xian    ta men shi yi dui en ai fu qi ,malloc shao le free jiu bi ran hui man man di si diao 。 cheng dui chu xian bu jin ti xian zai you duo shao ge malloc jiu ying gai you duo shao ge free, huan ti xian zai ta men ying jin liang chu xian zai tong yi han shu li ,“ shui shen qing , jiu you shui shi fang ”, kan xia mian de cheng xu : char * func(void) { char *p; p = (char *)malloc(…); if(p!=NULL) …; /* yi xi lie zhen dui p de cao zuo */ return p; } /* zai mou chu tiao yong func(), yong wan func zhong dong tai shen qing de nei cun hou jiang qi free*/ char *q = func(); … free(q);    shang shu dai ma wei fan le malloc he free de “ shui shen qing , jiu you shui shi fang ” yuan ze , dai ma de ou he du da , yong hu zai tiao yong func han shu shi xu que qie zhi dao qi nei bu xi jie ! zheng que de zuo fa shi : /* zai tiao yong chu shen qing nei cun , bing chuan ru func han shu */ char *p=malloc(…); if(p!=NULL) { func(p); … free(p); p=NULL; } /* han shu func ze jie shou shen shu p */ void func(char *p) { … /* yi xi lie zhen dui p de cao zuo */ }    gui ze 5 free hou yi ding yao zhi zhi zhen wei NULL, fang zhi qi cheng wei “ ye ” zhi zhen (9)“ han shu add bian yi sheng cheng de fu hao jiu shi add” int add(int x,int y) { return x + y; } float add(float x,float y) { return x + y; } [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867455.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo    ji bian shi zai C yu yan zhong ,add han shu bei duo shu C bian yi qi bian yi hou zai fu hao ku zhong de ming zi ye bu shi add, er shi _add。 er zai C++ bian yi qi zhong ,int add(int x,int y) hui bian yi cheng lei si _add_int_int zhe yang de ming zi ( cheng wei “mangled name”),float add(float x,float y) ze bei bian yi cheng _add_float _float,mangled name bao han le han shu ming 、 han shu shen shu shu liang ji lei xing xin xi ,C++ yi kao zhe zhong ji zhi lai shi xian han shu chong zai 。    suo yi , zai C++ zhong , ben zhi shang int add( int x, int y ) yu float add( float x, float y ) shi liang ge wan quan bu tong de han shu , zhi shi zai yong hu kan lai qi tong ming er yi 。    zhe jiu yao qiu chu xue zhe men neng tou guo yu fa xian xiang kan wen ti ben zhi 。 ben zhi shang , yu yan de chuang zao zhe men jiu shi zai wan ge zhong ge yang de hua yang , yi shi yu yan ju bei mou zhong neng li , pi ru mangled name hua yang de mu de zai yu shi C++ zhi chi chong zai 。 er C yu yan mei you wan zhe yang de hua yang , suo yi int add( int x, int y ) yu float add( float x, float y ) bu neng zai C cheng xu zhong tong shi cun zai 。 (10)“ mei jian guo zai C yu yan zhong tiao yong C++ de han shu ”、“C/C++ bu neng tiao yong Basic、Pascal yu yan de han shu ”    zhe you shi yi ge qi tian xia zhi da guai de wen ti ,“ da si wo dou bu xiang xin C、C++、basic、pascal de han shu neng xia tiao lai tiao qu ”, ke shi you ju hua zhe me shuo :    mei you ni jian bu dao de , zhi you ni xiang bu dao de !    ji ran fu rong jie jie ye you qi wen ming tian xia de dao li , na me C、C++、Basic、Pascal de han shu wei shen me jiu bu neng hu xiang tiao yong ne ?    neng !    ni ke yi yong Visual C++ xie yi ge DLL zai Visual Basic、Delphi(Pascal de sun zi ,Object Pascal de er zi ) zhong tiao yong , ye ke yi zai Visual Basic、Delphi zhong xie yi ge DLL zai Visual C++ zhong tiao yong bu shi ?    rang wo men lai tou guo xian xiang kan ben zhi 。 shou xian kan kan han shu de tiao yong yue ding ( yi Visual C++ lai shuo ming ):   (1) _stdcall tiao yong   _stdcall shi Pascal cheng xu de que sheng tiao yong fang shi , shen shu cai yong cong you dao zuo de ya zhan fang shi , bei tiao han shu zi shen zai fan hui qian qing kong dui zhan 。   WIN32 Api dou cai yong _stdcall tiao yong fang shi , zhe yang de hong ding yi shuo ming le wen ti :   #define WINAPI _stdcall   an C bian yi fang shi ,_stdcall tiao yong yue ding zai shu chu han shu ming qian mian jia xia hua xian , hou mian jia “@” fu hao he shen shu de zi jie shu , xing ru _functionname@number。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867482.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo   (2) _cdecl tiao yong   _cdecl shi C/C++ de que sheng tiao yong fang shi , shen shu cai yong cong you dao zuo de ya zhan fang shi , chuan song shen shu de nei cun zhan you tiao yong zhe wei hu 。_cedcl yue ding de han shu zhi neng bei C/C++ tiao yong , mei yi ge tiao yong ta de han shu dou bao han qing kong dui zhan de dai ma , suo yi chan sheng de ke zhi xing wen jian da xiao hui bi tiao yong _stdcall han shu de da 。    you yu _cdecl tiao yong fang shi de shen shu nei cun zhan you tiao yong zhe wei hu , suo yi bian chang shen shu de han shu neng ( ye zhi neng ) shi yong zhe zhong tiao yong yue ding 。 guan yu C/C++ zhong bian chang shen shu (…) de wen ti , bi zhe jiang ling wen xiang shu 。    you yu Visual C++ mo ren cai yong _cdecl tiao yong fang shi , suo yi VC zhong zhong tiao yong DLL shi , yong hu ying shi yong _stdcall tiao yong yue ding 。    an C bian yi fang shi ,_cdecl tiao yong yue ding jin zai shu chu han shu ming qian mian jia xia hua xian , xing ru _functionname。   (3) _fastcall tiao yong   _fastcall tiao yong jiao kuai , ta tong guo CPU nei bu ji cun qi chuan di shen shu 。    an C bian yi fang shi ,_fastcall tiao yong yue ding zai shu chu han shu ming qian mian jia “@” fu hao , hou mian jia “@” fu hao he shen shu de zi jie shu , xing ru @functionname@number。    yao hai zi _stdcall、_cdecl he _fastcall ke yi zhi jie jia zai han shu qian , ye ke yi zai Visual C++ zhong she zhi , ru tu 1。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867515.jpg[/img][/url]   tu 1 zai VC zhong she zhi han shu tiao yong yue ding    zai chuang jian DLL shi , yi ban shi yong _stdcall tiao yong (Win32 Api fang shi ), cai yong _functionname@number ming ming gui ze , yin er ge zhong yu yan jian de DLL neng hu xiang tiao yong 。 ye jiu shi shuo ,DLL de bian zhi yu ju ti de bian cheng yu yan ji bian yi qi wu guan , zhi yao zun shou DLL de kai fa gui fan he bian cheng ce lue , bing an pai zheng que de tiao yong jie kou , bu guan yong he zhong bian cheng yu yan bian zhi de DLL dou ju you tong yong xing 。    tui er guang zhi , jia ru you zhe yang yi ge IDE kai fa huan jing , ta neng shi bie ge zhong yu yan , suo you yu yan cai yong xiang tong de tiao yong yue ding he ming ming gui ze , yi ge ruan jian nei ge zhong yu yan shu xie de han shu jiang neng hu xiang tiao yong !    zhe ge shi jie shang ke neng yong yuan bu xu yao zhe yang yi ge IDE。 (11)“ ying yu 、 shu xue bu hao jiu xue bu hao C/C++” [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867774.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo    zhe ye xu shi 20 shi ji zui da de huang yan , zhe ju hua zui xian shi na wei da shi de ming ren ming yan yi wu ke kao zheng , ke ci hou yi pi pi de ren bei ta wu dao 。 xu duo chu xue zhe yin wei zhe ju hua bei xia dao , fang qi le zuo cheng xu yuan de li xiang 。 huan you xu duo hou lai cheng wei you xiu cheng xu yuan de ren , zai ta men de cheng chang guo cheng zhong bing mei you yi kao shen ao de shu xue , ke ta men huan shi zai zong jie jing yan shi zhi zao kong huang , hao cheng yi ding yao ju bei gao shen de shu xue zhi shi , wei kong bie ren xiao hua qi xue shu shui ping bu gao 。    zai xia ze ren wei , da duo shu qing kuang xia , cheng xu she ji bu xu yao tai shen ao de shu xue gong di , chu fei ni suo cong shi de cheng xu she ji she ji te ding de zhuan ye ling yu ( ru yu yin ji tu xiang chu li 、 shu zi tong xin ji shu deng )。 zai xia zhe yi guan dian ye xu shi ge jiu li xin , er ge ming bi ran yao liu xue xi sheng ( tan si tong ), suo yi gong hou da jia ban zhuan 。    na me ying yu zai C/C++ de xue xi zhong chu yu shen me di wei ne ? na jiu shi neng kan dong zi liao , kan dong MSDN。    xue bian cheng de zhong ji zhi dao bu zai kan shu , er zai da liang di bu duan di shi jian 。 (12)“C++ tai nan le , wo xue bu hui ”    you bu zhi shi shui de bei guan lun tiao , xu duo chu xue zhe bei C++ xia dao ,“ tai nan le , wo xue bu hao ”, ru ruo zhe zi lian 。 jia ru C++ zhen de nan dao xue bu hui , na me C++ de chuang zao zhe men suo cong shi de gong zuo qi bu shi “ fei ren li suo neng ji ye ”?        zai xia ren wei , xue xi C++ de tai du ying gai shi : zhan lue shang miao shi ta , zhan shu shang chong shi ta , yao gan yu sheng li (《 mao zhu xi yu lu 》)。 dang ran ye bu ke qing di , bu neng yin wei ba wo le yi dian pi mao jiu yi wei zi ji niu B hong hong le ( bi zhe zeng jing niu B hong hong le hao yi zhen zi , xian zai xiang lai , shen jiao dang shi you zhi )。    jia ru ni zheng fu le C++, tou che li jie le C++ de yu yan te xing ji STL, na me , qi ta yu yan xiang bu bei ni zheng fu dou nan le 。    ben hui shu zhe luo ci chu , geng duo cuo wu yu lu , dang ran shi dai xu 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785326.html][img]http://image.wangchao.net.cn/it/1323423867812.gif[/img][/url] geng duo nei rong qing kan C/C++ ji shu zhuan ti Java bian cheng kai fa shou ce zhuan ti , huo
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有