2009年11月9日 星期一
2009年11月5日 星期四
Connectting Windows Desktop on Linux
在ubuntu上有個rdesktop的套件,可以直接連上windows的遠端桌面 --- rdesktop,安裝後執行rdesktop ip即可連上windows的遠端桌面。
sudo apt-get install rdesktop rdesktop 172.23.19.243
2009年11月3日 星期二
C macro的誤用
macro主要是拿來取代,比如#define MAX_NUM 10,當用到MAX_NUM時,就會被轉成10,我們常用拿macro來define一些函數,比如:
#include <stdio.h> #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) int main(int argc, char *argv[]) { int x=10, y=11, big; big = MAX(++x, ++y); printf("the bigger + 1 = %d\n", big); return 0; }可是這裡就會發生問題了,當你使用CPP你可以看到,X全部被++x取代,而Y全部被++y取代,所以執行完的結果顯然就會錯誤了。
int main(int argc, char *argv[]) { int x=10, y=11, big; big = ((++x) > (++y) ? (++x) : (++y)); printf("the bigger + 1 = %d\n", big); return 0; }結果是13而不是12。 這邊應該改寫為
#include <stdio.h> #define MAX(x, y) \ ({ typeof(x) _x = (x); \ typeof(y) _y = (y); \ _x > _y ? _x : _y; }) int main(int argc, char *argv[]) { int x=10, y=11, big; big = MAX(++x, ++y); printf("the bigger + 1 = %d\n", big); return 0; }因為你無法預期使用者會輸入何種表示法,為了避免side effect,還是在內部宣告一個變數儲存使用者的輸入吧。 至於typeof可以參考一下GCC的說明http://gcc.gnu.org/onlinedocs/gcc/Typeof.html。
訂閱:
文章 (Atom)
熱門文章
-
轉自 http://www.wretch.cc/blog/redsonoma/14021073 基本概念: 1> tty(終端設備的統稱): tty一詞源於Teletypes,或者teletypewriters,原來指的是電傳打字機,是通過串行線用打印機鍵盤通過閱...
-
Work queue提供一個interface,讓使用者輕易的建立kernel thread並且將work綁在這個kernel thread上面,如下圖[1]所示。 由於work queue是建立一個kernel thread來執行,所以是在process context...
-
(V)將介紹file operations中的ioctl。ioctl的prototype為: int (*ioctl) (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); ...
-
這兩天電腦的word忽然都不能存檔,即便是另存新檔也不行,最後都只能放棄修改檔案,即便重新安裝過或者更新成2007也都不能存檔,最後就乖乖的google一下,原來是暫存的資料夾不存在,按照以下方式就可以解決了。 資料來源: word 2003不能存檔問題 編輯機碼的(reg...
-
System Call在HW和user space提供一層抽象層,主要目的有: 為user space提供硬體抽象層。比如,讀取檔案時,不用管檔案所在的媒體類型與檔案儲存類型。 System call能確保系統的安全與穩定。避免user space的無意或惡意的破壞。 ...
-
在kernel中建立thread可以使用kthread_create(),建立一個task,然後在調用wake_up_process(task)讓task真正的運行,如果要kill一個kthread可以使用kthread_stop()。 在kernel中,將kthread_cr...
-
Linux module練習手札I紀錄如何撰寫一個簡單的module,並且編輯它,以及load和unload一個module。 write a module #include <linux/init.h> #include <linux/module.h...
-
幾乎任何使用 TCP,UDP或UNIX-domain socket的動作都可以用nc來達成,常見的功能如。 simple TCP proxies shell-script based HTTP clients and servers network daemon testi...
-
很多人心中都有過一個問題 What is the difference between Platform driver and normal device driver? ,簡單的來說Platform devices就non-discoverable,也就是device本身沒辦法...
-
組成元件 要能正確顯示資料,必須包含資料倉儲(Store),資料欄位的定義(ColumnModel)。 首先我們先定義資料欄位: var cm = new Ext.grid.ColumnModel({ {header: 'Name', dataIndex...