Programming abstractions in C閱讀筆記:p127-p129
《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-something
(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)
浙公網安備 33010602011771號