Posted on May 16, 2010, 12:57 pm, by kcw, under
Programming.
關於 Cyclomatic complexity 一詞可參考 Wikipedia 上的解說。
中譯名稱是「循環複雜度」或者又稱為「迴圈複雜度」。主要是用來描述一個程式「條件分支」的複雜度,因為愈單純的 If-condition 愈容易讀懂,除錯時也較好發現問題所在。所以複雜度的數值,愈低愈好。在下面兩個情形複雜度的值都會加一:
if / while
switch-case
下列程式的 Cyclomatic complexity 分數是:2
foo()
{
if (condition)
printf ("hello");
}
下列程式的 Cyclomatic complexity 分數是:3
foo()
{
if (condition-X || condition-Y)
printf ("hello");
}
在 Cygwin 的 FAQ 中有提到:How do I uninstall all of Cygwin?
(1) 列出已安裝 cygwin service:cygrunsrv -L
(2) 停用並移除 Cygwin service:
cygrunsrv --stop [service_name]
cygrunsrv --stop inetd (參照 FAQ 說明)
cygrunsrv --remove [service_name]
(3) 砍掉 cygwin 目錄
(4) 移除註冊碼
HKEY_LOCAL_MACHINE\Software\Cygwin
HKEY_CURRENT_USER\Software\Cygwin
四月真是個練習程式的好日子,因為又到了每年論文趕稿時刻。左圖描述 MobileNode 類別與 Node 類別兩者間的關係,顯然 MobileNode 是 Node 的延伸類別。在 ns2 中如果想要得知節點的座標資訊,可以使用 getLoc() 這個函式。該函式定義在 mobilenode.h 底下,所以使用前記得引入這個標頭檔。函式內容如下:
class MobileNode : public Node
{
public:
inline void getLoc(double *x, double *y, double *z) {
update_position(); *x = X_; *y = Y_; *z = Z_;
}
}
使用方法是先將 Node 指標強制轉型成 MobileNode 指標再引用該函式。下面是一個小小的範例:
#include "mobilenode.h"
double x,y,z;
Node *p = Node::get_node_by_address(index);
((mobileNode *)p)->getLoc(&x, &y, &z);
回歸正題 [...]
proxytrace2any.cc: In function `int main(int, char**)':
proxytrace2any.cc:112: error: `IsLittleEndian' undeclared (first use this function)
proxytrace2any.cc:112: error: (Each undeclared identifier is reported only once for each function it appears in.)
proxytrace2any.cc:120: error: `ToOtherEndian' undeclared (first use this function)
make[1]: *** [proxytrace2any.o] Error 1
問題點在於「proxytrace2any.cc」這隻程式,因為使用到兩個未經定義(undeclared)的函數。修正方法:找到檔案 /indep-utils/webtrace-conv/dec/my-endian.h
將下列兩行註解起來:
#ifndef _ENDIAN_H_ 與
#endif
如同下面範例:
//#ifndef _ENDIAN_H_ ... 註解
#define _ENDIAN_H_
#include "proxytrace.h"
/* detects endian-ness */
int IsLittleEndian(void);
/* changes endian-ness */
void ToOtherEndian(TEntry *e);
//#endif [...]
int offset; // 宣告全域變數
int& set() // 回傳 Reference
{
return offset;
}
int main()
{
set()=13;
return 0;
}
第一次看到時覺得很奇怪。不過後來有人解說:當呼叫函數 set()時,會回傳一個參考值(Reference),此值是是指向 offset 這個變數。也就是說 set()執行結果:會回報一個Reference,而此「參考」本質上就是 offset 的別名。因此當使用「set()=13」時,表示間接執行「offset=13」這個動作。