C语言技巧

来源:互联网 发布:多益网络和37和4399 编辑:程序博客网 时间:2024/06/05 16:02

把自己学习C语言的技巧记录下来,以免忘记,每天至少一更


File I/O

1. Size of File Descriptor Table is limited. Make sure to close file descriptor when read and write in a large number of times.

2. Use following format to read and write content from/to files:

byte_read = read(infd, buf, BLKSIZE);...write(outfd, buf, byte_read);


Optimization

1. Use local variable rather than dynamic memory allocation to prevent memory leak.


String

1. Do not use equal sign, use strcpy instead.

2. 当在函数中初始化一个local char* 时,用bzero初始化


定义含有自身type的struct时, 直接用struct + 自身type。

typedef struct queue_node {    char* client;    struct queue_node *next;} queue_node_t;


0 0
原创粉丝点击