2013年3月19日
摘要: inode 保存文件系统对象的元信息数据(metadata)。当一个文件被创建时会分配一个 filename 和 inode number。/lost+found 存储发生意外后丢失的文件inode,只有 root 可以进入。查看某个文件的inode信息:stat a.txt File: `a.txt' Size: 5 Blocks: 8 IO Block: 4096 regular fileDevice: fd02h/64770d Inode: 13107232 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ richard) Gid: 阅读全文
posted @ 2013-03-19 16:37 chenkkkabc 阅读(235) 评论(0) 推荐(0) 编辑
  2013年3月17日
摘要: union除了用于节省空间,还有一些其他用法。1.省去位操作 bit masking / bit shiftingtypedef union { struct { unsigned char byte1; unsigned char byte2; unsigned char byte3; unsigned char byte4; } bytes; unsigned int dword;} HWRegister;...HWRegister reg;reg.dword = 0x12345678;reg.bytes.byte3 = 4;typedef union { ... 阅读全文
posted @ 2013-03-17 14:28 chenkkkabc 阅读(439) 评论(0) 推荐(0) 编辑
  2013年3月15日
摘要: 字节层次上_Bool is_little_endian() { int a = 1; char* p = (char*)&a; return *p == 1;}或_Bool is_little_endian() { union { int a; char b; } u; u.a = 1; return u.b == 1;}位层次上_Bool is_little_endian() { union { unsigned char a; struct { unsigned char b0 : 1; unsigned char : 7; ... 阅读全文
posted @ 2013-03-15 15:25 chenkkkabc 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 一般可以把 Endian 理解成 Byte Order(字节序),Bit Order 通常和 Byte Order 一致。big-endian: MSB(Most Significant Byte) first,存放在低地址,又叫做网络序SPARC, PowerPC, Motorola 68000等处理器采用little-endian: LSB(Least Significant Byte) first,存放在低地址x86, VAX等处理器采用ARM, MIPS, DEC Alpha等处理器是可配置的 阅读全文
posted @ 2013-03-15 13:05 chenkkkabc 阅读(147) 评论(0) 推荐(0) 编辑
  2013年3月14日
摘要: ANSI:American National Standards Institute美国国家标准协会,是制定美国国家标准的非盈利组织,是ISO和IEC的成员。K&R C The C Programming Language, 1978, byKernighan & RitchieC89ANSI X3.159-1989C90ISO/IEC 9899:1990C99ISO/IEC 9899:1999C11ISO/IEC 9899:2011__STDC__ 定义这个宏为 1 就符合ANSI C标准。 阅读全文
posted @ 2013-03-14 20:59 chenkkkabc 阅读(183) 评论(0) 推荐(0) 编辑
  2013年3月12日
摘要: Trident代表 Internet ExplorerTasman代表 IE for MacKHTML代表 KonquerorWebKit代表 Safari、Chrome、Web(Epiphany)Gecko代表 FirefoxPresto代表 Opera可以通过JS的 navigator.userAgent 获得浏览器相关信息。 阅读全文
posted @ 2013-03-12 20:46 chenkkkabc 阅读(98) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>void f() { printf("function\n"); }#define f() printf("macro\n")int main() { f(); // macro (f)(); // function return 0;}函数名加括号 阅读全文
posted @ 2013-03-12 20:32 chenkkkabc 阅读(398) 评论(0) 推荐(0) 编辑
  2013年3月11日
摘要: #define OFFSET(TYPE,MEM) ((size_t)&(((TYPE*)0)->MEM)) 阅读全文
posted @ 2013-03-11 21:22 chenkkkabc 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #define NELEMENTS(array) (sizeof(array) / sizeof((array)[0])) 阅读全文
posted @ 2013-03-11 21:19 chenkkkabc 阅读(541) 评论(0) 推荐(0) 编辑
摘要: _Bool is_power_of_2(unsigned int n) { if (n == 0) { return false; } return (n & (n-1)) == 0;} 阅读全文
posted @ 2013-03-11 21:06 chenkkkabc 阅读(188) 评论(0) 推荐(0) 编辑