Set breakpoint at specified line or function.
Argument may be line number, function name, or "*" and an address.
If line number is specified, break at start of code for that line.
If function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no arg, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.
Multiple breakpoints at one place are permitted, and useful if conditional.
Do "help breakpoints" for info on other commands dealing with breakpoints.
会初始化下图所C的数据l果: +---+---+---+---+---+---+
a: | h | e | l | l | o |\0 |
+---+---+---+---+---+---+
+-----+ +---+---+---+---+---+---+
p: | *======> | w | o | r | l | d |\0 |
+-----+ +---+---+---+---+---+---+
Ҏ x 是数l还是指? cM x[3] q样的引用会生成不同的代码。认识到q一点大有裨益。以上面的声明ؓ? 当编译器看到表达? a[3] 的时? 它生成代码从 a 的位|开始蟩q?3 ? 然后取出那个字符. 如果它看?p[3], 它生成代码找?``p" 的位|? 取出其中的指针? 在指针上?3 然后取出指向的字W。换a? a[3] ?名ؓ a 的对?(的v始位|? 之后 3 个位|的? ?p[3] ? p 指向的对象的 3 个位|之后的? 在上例中, a[3] ? p[3] y都是 'l' , 但是~译器到N里的途径不尽相同。本质的区别在于cM a 的数l和cM p 的指针一旦在表达式中出现׃按照不同的方法计? 不论它们是否有下标。下一问题l箋深入解释?参见问题 1.13?
参考资料: [K&R2, Sec. 5.5 p. 104]; [CT&P, Sec. 4.5 pp. 64-5]?
]]>A Note on TMinhttp://m.tkk7.com/zellux/archive/2007/09/19/146605.htmlZelluXZelluXWed, 19 Sep 2007 13:26:00 GMThttp://m.tkk7.com/zellux/archive/2007/09/19/146605.htmlhttp://m.tkk7.com/zellux/comments/146605.htmlhttp://m.tkk7.com/zellux/archive/2007/09/19/146605.html#Feedback1http://m.tkk7.com/zellux/comments/commentRss/146605.htmlhttp://m.tkk7.com/zellux/services/trackbacks/146605.html
Summary
Due to one of the rules for processing integer constants in ANSI C,
the numeric constant -2147483648 is handled in a peculiar
way on a 32-bit, two's complement machine.
The problem can be corrected by writing
-2147483647-1, rather than
-2147483648 in any C code.
Description of Problem
The ANSI C standard requires that an integer constant too large to be
represented as a signed integer be ``promoted'' to an unsigned value.
When GCC encounters the value 2147483648, it gives a warning message:
``warning: decimal constant is so large that it is
unsigned.'' The result is the same as if the value had been
written 2147483648U.
ANSI C标准中要求太大的整型帔R都表CZؓunsigned
The compiler processes an expression of the form -X
by first reading the expression X and then
negating it. Thus, when the C compiler encounters the constant
-2147483648, it first processes 2147483648,
yielding 2147483648U, and then negates it. The unsigned
negation of this value is also 2147483648U. The bit
pattern is correct, but the type is wrong!
书上的一个小错误
Writing TMin in Code
The ANSI C standard states that the maximum and minimum integers
should be declared as constants INT_MAX and
INT_MIN in the file limits.h. Looking at
this file on an IA32 Linux machine (in the directory
/usr/include), we find the following declarations:
/* Minimum and maximum values a `signed int' can hold. */
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX - 1)
This method of declaring INT_MIN avoids accidental
promotion and also avoids any warning messages by the C compiler about
integer overflow.
The following are ways to write TMin_32 for a 32-bit machine that give
the correct value and type, and don't cause any error messages:
-2147483647-1
(int) 2147483648U
1<<31
The first method is preferred, since it indicates that the
result will be a negative number.
表示-2147483648的几U方?br />
]]>APUE - File I/O (5)http://m.tkk7.com/zellux/archive/2007/08/22/138633.htmlZelluXZelluXWed, 22 Aug 2007 07:46:00 GMThttp://m.tkk7.com/zellux/archive/2007/08/22/138633.htmlhttp://m.tkk7.com/zellux/comments/138633.htmlhttp://m.tkk7.com/zellux/archive/2007/08/22/138633.html#Feedback0http://m.tkk7.com/zellux/comments/commentRss/138633.htmlhttp://m.tkk7.com/zellux/services/trackbacks/138633.html#include <unistd.h> int dup(int filedes); int dup2(int filedes, int filedes2); // Both return: new file descriptor if OK, -1 on error
]]>APUE - File I/O (3) - File Sharinghttp://m.tkk7.com/zellux/archive/2007/08/20/138233.htmlZelluXZelluXMon, 20 Aug 2007 14:39:00 GMThttp://m.tkk7.com/zellux/archive/2007/08/20/138233.htmlhttp://m.tkk7.com/zellux/comments/138233.htmlhttp://m.tkk7.com/zellux/archive/2007/08/20/138233.html#Feedback0http://m.tkk7.com/zellux/comments/commentRss/138233.htmlhttp://m.tkk7.com/zellux/services/trackbacks/138233.htmlEvery process has an entry in the process table. Within each process table entry is a table of open file descriptors, which we can think of as a vector, with one entry per descriptor. Associated with each file descriptor are 1) The file descriptor flags (close-on-exec; refer to Figure 3.6 and Section 3.14) 2) A pointer to a file table entry
The kernel maintains a file table for all open files. Each file table entry contains 1) The file status flags for the file, such as read, write, append, sync, and nonblocking 2) The current file offset 3) A pointer to the v-node table entry for the file
Each open file (or device) has a v-node structure that contains information about the type of file and pointers to functions that operate on the file. For most files, the v-node also contains the i-node for the file. This information is read from disk when the file is opened, so that all the pertinent information about the file is readily available. For example, the i-node contains the owner of the file, the size of the file, pointers to where the actual data blocks for the file are located on disk, and so on.
]]>APUE - File I/O (2) http://m.tkk7.com/zellux/archive/2007/08/13/136516.htmlZelluXZelluXMon, 13 Aug 2007 14:14:00 GMThttp://m.tkk7.com/zellux/archive/2007/08/13/136516.htmlhttp://m.tkk7.com/zellux/comments/136516.htmlhttp://m.tkk7.com/zellux/archive/2007/08/13/136516.html#Feedback0http://m.tkk7.com/zellux/comments/commentRss/136516.htmlhttp://m.tkk7.com/zellux/services/trackbacks/136516.htmlThe file's offset can be greater than the file's current size, in which case the next write to the file will extend the file. This is referred to as creating a hole in a file and is allowed. Any bytes in a file that not been written are read back as 0. A
hole in a file isn't required to have storage backing it on disk.
Depending on the file system implementation, when you write after
seeking past the end of the file, new disk blocks might be allocated to
store the data, but there's no need to allocate disk blocks for the
data between the old end of file and t he location where you start
writing.
2. read Function #include <unistd.h> ssize_t read(int filedes, void *buf, size_t nbytes); // Returns: number of bytes read, 0 if end of file, -1 on error
readd的字节数于所要求的字节数的几U可能:
1) 从文件中dQ在所要求的字节数d完成前到达文件尾?br>
2) 从终端读取,q种情况下通常每次最多读取一行内宏V?br>
3) 通过|络dQ网l缓冲可能导致读取到于要求的字节数?br>
4) 从管道或者FIFO中读?br>
5) 从record-oriented讑֤中读取,如磁带,每次臛_q回一个记录。orz...
6) 在一定数量的数据d后被信号中断?br>
3. write Function
#include <unistd.h>
ssize_t write(int filedes, const void *buf, size_t nbytes);
// Returns: number of bytes written if OK, -1 on error
D错误的通常原因是磁盘已满,或者超Zl定q程的文件大限制?
]]>~译《UNIX环境高~程》中的第一个程?/title>http://m.tkk7.com/zellux/archive/2007/08/03/134139.htmlZelluXZelluXThu, 02 Aug 2007 17:13:00 GMThttp://m.tkk7.com/zellux/archive/2007/08/03/134139.htmlhttp://m.tkk7.com/zellux/comments/134139.htmlhttp://m.tkk7.com/zellux/archive/2007/08/03/134139.html#Feedback1http://m.tkk7.com/zellux/comments/commentRss/134139.htmlhttp://m.tkk7.com/zellux/services/trackbacks/134139.html/tmp/cceQcwN0.o: In function `main': myls.c:(.text+0x24): undefined reference to `err_quit' myls.c:(.text+0x5b): undefined reference to `err_sys' collect2: ld q回 1
int main(int argc, char* argv[]) { DIR *dp; struct dirent *dirp;
if (argc !=2) err_quit("a single argument (the directory name) is required");
if ( (dp = opendir(argv[1])) == NULL) err_sys("can't open %s", argv[1]);
while ( (dirp = readdir(dp)) != NULL) printf("%s\n", dirp->d_name);
closedir(dp); exit(0); }
$ gcc myls.c libmisc.a 出现几个WarningQ?br>libmisc.a(strerror.o): In function `strerror': strerror.c:(.text+0x18): warning: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead strerror.c:(.text+0xf): warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead 看来q本书的太老了 $ ./a.out . ׃列出当前目录下的所有文?br>
但是在自己机器上~译时报错了Q可能连接器版本较高Q会自动扑ևq种错误 /usr/bin/ld: Warning: alignment 4 of symbol `x' in /tmp/ccupQXSG.o is smaller than 8 in /tmp/ccNNG9XZ.o 是double和int大小不义D的对齐问?br>
]]>C 学习W记 (2)http://m.tkk7.com/zellux/archive/2007/07/12/129904.htmlZelluXZelluXThu, 12 Jul 2007 11:33:00 GMThttp://m.tkk7.com/zellux/archive/2007/07/12/129904.htmlhttp://m.tkk7.com/zellux/comments/129904.htmlhttp://m.tkk7.com/zellux/archive/2007/07/12/129904.html#Feedback0http://m.tkk7.com/zellux/comments/commentRss/129904.htmlhttp://m.tkk7.com/zellux/services/trackbacks/129904.htmlAlgorithm in C上的ҎQ这U方法好处在于t[i]是指向各行首的指针,cM于Java的数l;而如果直接用malloc分配m*n*sizeof(int)大小的空_则没有这U效果,cM于C#中的[,]数组 int **malloc2d(int r, int c) { int i; int **t = malloc(r * sizeof(int *)); for (i = 0; i < r; i++) t[i] = malloc(c * sizeof(int)); return t; }
]]>几个C的字W串操作代码http://m.tkk7.com/zellux/archive/2007/07/08/128923.htmlZelluXZelluXSun, 08 Jul 2007 13:05:00 GMThttp://m.tkk7.com/zellux/archive/2007/07/08/128923.htmlhttp://m.tkk7.com/zellux/comments/128923.htmlhttp://m.tkk7.com/zellux/archive/2007/07/08/128923.html#Feedback2http://m.tkk7.com/zellux/comments/commentRss/128923.htmlhttp://m.tkk7.com/zellux/services/trackbacks/128923.html1. 计算串长?strlen(a) for (i = 0; a[i] != 0; i++); return i;
2. 复制 strcpy(a, b) for (i = 0; (a[i] = b[i]) != 0; i++);
3. 比较 strcmp(a, b) for (i = 0; a[i] == b[i]; i++) if (a[i] == 0) return 0; return a[i] - b[i]; 注意适用于不同长度的字符?br> 指针版本 1. strlen(a) b = a; while (*b++); return b - a - 1;
2. strcpy(a, b) while (*a++ = *b++);
3. strcmp(a, b) while (*a++ = *b++) if (*(a-1) == 0) return 0; return *(a-1) - *(b-1);
]]>C++ 入门W记(3)http://m.tkk7.com/zellux/archive/2007/06/03/121672.htmlZelluXZelluXSun, 03 Jun 2007 10:58:00 GMThttp://m.tkk7.com/zellux/archive/2007/06/03/121672.htmlhttp://m.tkk7.com/zellux/comments/121672.htmlhttp://m.tkk7.com/zellux/archive/2007/06/03/121672.html#Feedback0http://m.tkk7.com/zellux/comments/commentRss/121672.htmlhttp://m.tkk7.com/zellux/services/trackbacks/121672.html1. 关于函数指针 The C++ Programming Language上的一D늤例代码: map<string, int> histogram;
其中record和print是以函数指针的Ş式传递给for_each的。感觉这U方法最清晰、直接?br/>Javag更多的是用接口来辑ֈcM的效果的Q比如Collections.sort(Comparable)Q通常通过匿名内部cLq行自定义元素的比较Q从而排序。但是这在语义上已经不是函数了,而是被排序对象解释为实CComparable接口的对象?br/>另外Java反射机制中也有MehodҎQ觉得也可以通过传递Methodc,然后在sortҎ中调用这个Method的invokeҎQ这应该更接q函数指针的语义。但没看到过q样的实例?br/>C#则引入了委托的概念,通过delegate关键字声明该Ҏ。多一个关键字感觉是啰唆了点?-,- 现在开始对W一ơ在Thinking in Java中看到的Callback回调机制有了一Ҏ觉。当时看的时候很隄解?br/>看来在学习某一门语a的时候有一定其他语a的背景进行比较,很容易加q解?/p>