example code:
enum
{
A = 1U << 2;
...
}
同等代表 A = 0x1 <<2;
但 1U 代表啥意思呢?
是告訴 compilor, "1" 要用所指定的型別來存.
在不同的平台或complior 才會有相同的大小來存enum最大值.
而不會因平台或complior有不同的結果.
如: U 為 unsigned int ==> 以64-bit 來存, 表enum中最大值為 0xFFFFFFFF; U 為 unsidned char ==> 8-bit 來存, 表enum中最大值為 0xFF.
或是可用另一種寫法:
enum
{
A = 1 << 2;
...
E = 0xFF
}
表enum中最大值為 0xFF.
Cool~ Linux 是考驗程式能力的最佳途徑
2009年4月24日 星期五
2009年4月21日 星期二
C語言不定參數的應用
From: http://magicalloveshe.blogspot.com/2008/06/variable-argument.html
不定參數
就是傳入函式的參數是不固定的
可多可少
例如printf
int printf(const char *format [,argument]...);
那個中括號括起來的arguement可多可少
而且還可以不同型態
這就是不定參數
....
Reference web:
http://ehome.hifly.to/showthread.php?s=&threadid=329
http://blog.yam.com/ddy1280/article/2095414
http://magicalloveshe.blogspot.com/2008/06/variable-argument.html
http://blog.csdn.net/arong1234/archive/2008/05/18/2456455.aspx
http://www.itwis.com/html/c/clang/20080519/1511.html
不定參數
就是傳入函式的參數是不固定的
可多可少
例如printf
int printf(const char *format [,argument]...);
那個中括號括起來的arguement可多可少
而且還可以不同型態
這就是不定參數
....
Reference web:
http://ehome.hifly.to/showthread.php?s=&threadid=329
http://blog.yam.com/ddy1280/article/2095414
http://magicalloveshe.blogspot.com/2008/06/variable-argument.html
http://blog.csdn.net/arong1234/archive/2008/05/18/2456455.aspx
http://www.itwis.com/html/c/clang/20080519/1511.html
訂閱:
文章 (Atom)