C/C++
文章平均质量分 80
nanyo
这个作者很懒,什么都没留下…
展开
-
C语言之各种符号
*****comment*****/**/这种习惯的注释不能嵌套。编译器会将注释部分剔除,但不是简单的删除,而是用空格代替原来的注释,比如int/*...*/i是合法的,但in/*...*/t i不合法。y = x/*p编译出错,编译器把/*当成一段注释的开始。y = x/ *p或y = x/(*p)正确。*****back slash***原创 2012-09-28 03:53:27 · 1228 阅读 · 0 评论 -
APUE2e之signal function, signal handler, and signal mask on Ubuntu
When I was trying to run the program in Figure 10.23 in APUE2e using Ubuntu command line, after I typed Ctrl+C twice, the program terminated, which meant that the second SIGINT signal generated was no原创 2012-09-28 04:42:24 · 361 阅读 · 0 评论 -
APUE2e之Exercise 8.2
vfork v.s. fork/* * exercise8-2.c * * Created on: Nov 10, 2011 * Author: zhuhuang */ #include int glob = 6; int callvfork(void){ int var=88; pid_t pid; //compare the ru原创 2012-09-28 04:39:12 · 237 阅读 · 0 评论 -
APUE2e之Exercise 3.2
My implementation for APUE2e Exercise3.2: implement my own dup2 function that performs the same service as the dup2 function. Based on a little testing, it seems to work and behave as the provided d原创 2012-09-28 04:36:09 · 286 阅读 · 0 评论 -
C语言之大小端模式
//little endian: the least significant byte at lowest address.//big-endian: the most significant byte at lowest address.int checkSystem(){ //union size is the largest size of its fields. And all原创 2012-09-28 03:56:20 · 802 阅读 · 0 评论 -
APUE2e之Exercise 16.3 Solution B
Code for client side is in Figure 16.14 in APUE2e, Page 568.To compile the program, check this post: posix thread相关函数的编译(undefined reference to `pthread_create’)/** * apue-chap16: ex原创 2012-09-28 04:50:05 · 1003 阅读 · 0 评论 -
APUE2e之Exercise 10.11
/** * apue-chap10: exercise10-11.c * * Description: TODO * * Created On: Mar 1, 2012 * * @author: Huang Zhu * * @email: zhuhuang.zp@gmail.com */ //Run under Ubuntu 10.04. sig_intr is n原创 2012-09-28 04:48:03 · 444 阅读 · 0 评论 -
APUE2e之Exercise 10.6 Solution C
Using Standard I/O Library to read and write the file. Rather than using signal function, I used sigaction. Thus don’t need to call TELL_WAIT in the for body./** * apue-chap10: exercise10-原创 2012-09-28 04:46:51 · 548 阅读 · 0 评论 -
APUE2e之Exercise 10.6 Solution B
Using Standard I/O Library to read and write the file./** * apue-chap10: exercise10-6b.c * * Description: Standard I/O Library * * Created On: Feb 16, 2012 * * @author: Huang Zhu *原创 2012-09-28 04:45:53 · 858 阅读 · 0 评论 -
APUE2e之Exercise 10.6 Solution A
Using File I/O to read and write the file./** * apue-chap10: exercise10-6a.c * * Description: FILE I/O * * Created On: Feb 15, 2012 * * @author: Huang Zhu * * @email: zhuhuang.zp@gm原创 2012-09-28 04:45:00 · 352 阅读 · 0 评论 -
APUE2e之Exercise 8.7
close-on-exec flag/* * exercise8-7.c * * Created on: Nov 11, 2011 * Author: zhuhuang */ #include #include #include #include int main(void){ DIR *dir; int filedes1, filede原创 2012-09-28 04:40:22 · 257 阅读 · 0 评论 -
APUE2e之Exercise 3.6
I was working exercise3.6 of APUE2e and the code was simple. But when I tried to use fgets and fputs to print out the file content, I got problems. Then I tried to figure out the reason. It turned out原创 2012-09-28 04:37:26 · 257 阅读 · 0 评论 -
C++之Access Label, Inheritance, and Friend
************Inheritance************Three modes of inheritance in C++: public, protected, private. For example: class D: public A, protected B, private C. (A, B, C, D are all class types)class原创 2012-09-28 04:07:25 · 285 阅读 · 0 评论 -
C语言之各种关键字
C语言32个关键字:auto, int, double, long, char, float, short, signed, unsigned, struct, union, enum, static, switch, case, default, break, register, const, volatile, typedef, extern, return, void, continue,原创 2012-09-28 03:50:38 · 785 阅读 · 0 评论 -
C语言之预处理
ANSI C预处理命令:#define, #undef, #include, #if, #else, #elif, #endif, #ifdef, #ifndef, #line, #error, #pragmaANSI C宏:_LINE_:表示正在编译的文件的行号_FILE_:表示在横在编译的文件的名字_DATE_:表示编译时刻的日期字符串,例如“25 De原创 2012-09-28 03:54:26 · 776 阅读 · 0 评论 -
C语言之数组与指针
*******数组首元素的地址 vs 数组首地址*******/*a: bff0660ca+1: bff06610&a: bff0660c&a+1: bff06620*/int a[5] = {1,2,3,4,5};printf("a: %x\n", a); //address of first element in the arrayprintf("a+1原创 2012-09-28 03:57:19 · 736 阅读 · 0 评论 -
APUE2e之Exercise 16.3 Solution A
Below is the code for the server side. Code for client side is in Figure 16.14 in APUE2e, Page 568.To compile the program, check this post: posix thread相关函数的编译(undefined reference to `pthread_crea原创 2012-09-28 04:49:12 · 280 阅读 · 0 评论