乐趣区

关于c:Programming-abstractions-in-C阅读笔记p127p129

《Programming Abstractions In C》学习第 51 天,p127-p129,总结如下:

一、技术总结

1. string library

把握罕用函数如 strlen,strcpy 用法。

2.buffer overflow(缓冲区溢出)

(1) 什么是 buffer?

p129,Arrays that are preallocated and later use as a repository for data called buffers。

(2) 什么是缓冲区溢出?

p129,Writing data past the end of an buffer is a common programming error called buffer overflow。

//buffer overflow 示例
char *src = "Hello";
char dst[1]; // dst 称为 buffer

strcpy(dst, src); // 该操作会导致 buffer overflow 问题 

书中只是做一个简略的阐明,具体可参考:

(1) wikipedia, Buffer overflow: https://en.wikipedia.org/wiki/Buffer_overflow

二、英语总结

1.“The function will go ahead and copy characters right on past the end of the buffer.”语法分析

答:这里的应该是 The function will go ahead and (copy characters right) (on past the end of the buffer),这句话有几个要留神的中央:

(1)right

adv. exactly or all the way(齐全地),指的是“始终复制 / 持续复制”。在原文中也有一点 ” 强调 ” 的意思 – 尽管字符串曾经超过了缓冲区的长度 (Buffersize),然而 strcpy 函数还是会复制。当然,副词在句子中往往能够疏忽,间接了解为 copy 也是能够的。

(2)on the end

这里之所以用 on,可能是因为 data 对 buffer 而言是 on,例如:I have a pimple right on the end of my nose。参考:https://ell.stackexchange.com/questions/111682/on-the-end-of-…

(3)past

这里为什么应用 past 呢?如果不必,那么 on the end of buffer 也说得通。这里之所以用 past,示意曾经超过了缓冲区,past 取“prep. to a position that is further than a particular point”之意。

2.obligation 什么意思?

答:

(1)oblige:ob-(“to”) + ligare(“to bind”),to bind by oath(以誓言束缚)。

(2)oblige > obligation:obligation 的意思是“n. the fact that you are obliged to do sth”(任务,责任)

p129,”you have an obligation to check the length of the source string before you copy it using strpy”。

3.equivalent of 语法分析

答:p129,“Thus,the Pig Latin equivalent of any is anyway”,初看到这句话的时候心里是困惑的,因为记忆中都是把 equivalent 当做形容词用,前面接 to。这里接 of,那么就是用作名词:n. sth that has the same amount,value, purpose etc as sth else。

三、参考资料

1. 编程

(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414

2. 英语

(1)Etymology Dictionary:https://www.etymonline.com

(2) Cambridage Dictionary:https://dictionary.cambridge.org

欢送搜寻及关注:编程人 (a_codists)

退出移动版