全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1508
推到 Plurk!
推到 Facebook!

用 假指令 #if 除錯的問題

尚未結案
small77
一般會員


發表:5
回覆:8
積分:2
註冊:2005-10-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-14 14:17:21 IP:211.74.xxx.xxx 未訂閱
請問以下 二種 除錯 方法 應該選用何種 (考慮到程式寫的很大時)    [註]    如果像 test() 參數很少 我會直接寫成     
    void test (int *index, int lb, int ub, int *NN, int lb2, int ub2)
{      int place, w;      for(w=lb; w<=ub; w  ) 
  {         place = index[w];         #if _check_error
        if (place < lb2) printf(" 超過陣列 下限 ");
        if (place > ub2) printf(" 超過陣列 上限 ");  
     #endif         NN_2[place] = 1;      }
 
}    
但我實際的函式是 參數非常多 有些參數 只有在除錯時 才會用到 ///////////////////////////////////////////////////////////// [第一種方法] 缺點: 除錯時 呼叫時麻煩
    void test (int *index,
           int lb,
           int ub,
           int *NN,               #if _check_error
             ,
                              
              struct array_ifo   NN_array_ifo               #endif
          )    {      int place, w;      for(w=lb; w<=ub; w  ) 
  {       place = index[w];       #if _check_error
      if (place < NN_array_ifo.lb) printf(" 超過陣列 下限 ");
      if (place > NN_array_ifo.ub) printf(" 超過陣列 上限 ");  
   #endif       NN_2[place] = 1;
 
  }     
}    
///////////////////////////////////////////////////////////// [第二種方法]
    struct array_ifo  NN_array_ifo;    struct array_ifo    Get_NN_array_ifo()
{       return  NN_array_ifo;
}    void test (int *index,
           int lb,
           int ub,
           int *NN
          )
{      #if _check_error        struct array_ifo NN_array_ifo  = Get_NN2_arifo();      #endif      int place, w;      for(w=lb; w<=ub; w  ) 
  {       place = index[w];       #if _check_error
      if (place < NN_array_ifo.lb) printf(" 超過陣列 下限 ");
      if (place > NN_array_ifo.ub) printf(" 超過陣列 上限 ");  
   #endif       NN[place] = 1;
 
  }    }    
small77
一般會員


發表:5
回覆:8
積分:2
註冊:2005-10-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-10-14 14:23:48 IP:211.74.xxx.xxx 未訂閱
抱歉 [第二種方法] 寫錯一些地方 更正如下 struct array_ifo NN_array_ifo; struct array_ifo Get_NN_array_ifo() { return NN_array_ifo; } void test (int *index, int lb, int ub, int *NN ) { #if _check_error struct array_ifo NN_array_ifo = Get_NN_array_ifo(); #endif int place, w; for(w=lb; w<=ub; w ) { place = index[w]; #if _check_error if (place < NN_array_ifo.lb) printf(" 超過陣列 下限 "); if (place > NN_array_ifo.ub) printf(" 超過陣列 上限 "); #endif NN[place] = 1; } }
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-10-14 15:30:52 IP:211.22.xxx.xxx 未訂閱
不確定是否有看懂你的意思如果是在考慮除錯與否來決定參數的個數問題,不必要寫的那麼麻煩~看看 class="code"> void test(int *index,int lb,int ub,int *NN,struct array_ifo *pNN_array_ifo); void test(int *index,int lb,int ub,int *NN); 或者不定參數 void test(int *index,int lb,int ub,...); http://delphi.ktop.com.tw/topic.php?topic_id=73106 請查閱一下C++的手冊。 -----------------------
系統時間:2024-04-29 16:12:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!