發表文章

目前顯示的是 3月, 2011的文章

[c] fork

fork will return 0 when it is child process and a random positive number when it is parent.

[c] error: ‘exit’ was not declared in this scope

error: ‘exit’ was not declared in this scope it will be compiled without errors if you include in your code the statement: #include <cstdlib> error: ‘fork’ was not declared in this scope it will be compiled without errors if you include in your code the statement: #include <unistd.h>

[c++] size_t

Unsigned integral type size_t corresponds to the integral data type returned by the language operator sizeof and is defined in the header file (among others) as an unsigned integral type. In , it is used as the type of the parameter num in the functions memchr, memcmp, memcpy, memmove, memset, strncat, strncmp, strncpy and strxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect. It is also used as the return type for strcspn, strlen, strspn and strxfrm to return sizes and lengths.

[c++] static 的意義

1.用作變數: 1-1:放在函數內 Ex: void MyFun() { static int i=0; } 說明:"i"為"static,i"的生命週期會到程式結束,但是他的scope 還是在MyFun()中,每次呼叫MyFun(),函數中"i"的值會保留上次呼叫最後一次設定的值。 1-2:放在函數外 Ex:檔案 abc.c 中寫了如下 static int s_i=0; int myfun() {} 說明:此時"s_i"只能在檔案"abc.c"中使用,她可以讓"abc.c"中所有的"function"看到,他的生命週期也是到程式結束,但是別的.c 檔是無法使用到"abc.c"檔中的"s_i"。 2.在function 前面加上"static" Ex:檔案 123.c 中寫了如下 static void MyFun() {return;} 說明:此時"MyFun()"只能給這個123.c 這個檔案中的其他function 呼叫。 (簡單的說,就是"MyFun()"這個function不會被linker 參考到) 資料來源:http://flykof.pixnet.net/blog/post/23583952