首页 > 其他分享 >Programming abstractions in C阅读笔记:p127-p129

Programming abstractions in C阅读笔记:p127-p129

时间:2023-08-24 21:45:36浏览次数:37  
标签:p127 end abstractions buffer Programming p129 past https overflow

《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)

标签:p127,end,abstractions,buffer,Programming,p129,past,https,overflow
From: https://www.cnblogs.com/codists/p/17655233.html

相关文章

  • CSAPP Notes ML Programming
    CSAPPNotes:MLProgrammingComputerSystem-Notes:MLProgramming本课程主要使用x86指令;CISC(复杂指令集);ARM属于RISC(精简指令集);g++和gccg++和gcc都是GNUCompilerCollection(GNU编译器集合)中的工具,用于编译源代码并生成可执行文件。然而,它们之间有一些区......
  • Programming abstractions in C阅读笔记:p123-p126
    《ProgrammingAbstractionsInC》学习第50天,p123-p126,总结如下:一、技术总结1.notaion这也是一个在计算机相关书籍中出现的词,但有时却不是那么好理解,因为它可以指代很多对象,这里做一个记录。示例:p124。InC,youcanuseanycharacterarraytoholdstringdata.charstr[6]={......
  • The 2023 ICPC China Shaanxi Provincial Programming Contest
    链接:https://qoj.ac/contest/1290A表达式板子。\(O(|s|)\)。#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);strings;cin>>s;intn=s......
  • Programming abstractions in C阅读笔记: p118-p122
    《ProgrammingAbstractionsInC》学习第49天,p118-p122,总结如下:一、技术总结1.随机数(1)seedp119,"Theinitialvalue--thevaluethatisusedtogettheentireprocessstart--iscallaseedfortherandomgenerator."二、数学总结1.均匀分布(uniformdistribution)......
  • Programming abstractions in C阅读笔记: p114-p117
    《ProgrammingAbstractionsinC》学习第48天,p114-p117,​总结如下:一、技术总结主要通过randomnumber介绍了随机数的相关用法,interface​示例(random.h)​,clientprogram示例(craps.c)。#include<stdio.h>#include"genlib.h"#include"random.h"staticboolTryToMakePo......
  • The 13th Northeast Collegiate Programming Contest
    ProblemB.BalancedDiet其实就是对每种糖果从大到小的排序后,计算前缀和后再\(O(n)\)处理,由于最多只有\(n\)个糖果,所以最大复杂度是\(O(nlogn)\)。对于题目给的每种糖果的限制\(limit\),就把当前小于\(limit\)的贡献加到\(max(limit,i)\)上。vector<int>g[N];voids......
  • the-c-programming-language-reading-notes
    TheCProgrammingReadingNotesCreated:2023-06-06T15:59+08:00Published:2023-08-16T12:14+08:00Categories:C|ReadingNotes我看的是第二版,解决了初学C语言和OS课程的时候的一些疑惑,比如:extern的使用,原来function和object没有什么区别,比如下面的代码,将a和......
  • Programming abstractions in C阅读笔记p111-p113: boilerplate
    《ProgrammingAbstractionsInC》学习第47天,p111-p113,总结如下:一、技术总结1.boilerplate/**File:random.h*Version:1.0*LastmodifiedonFriJul2216:44:361994byeroberts*-----------------------------------------------------*Thisinterfacepr......
  • Programming abstractions in C阅读笔记p111-p113: boilerplate
    《ProgrammingAbstractionsInC》学习第47天,p111-p113,总结如下:一、技术总结1.boilerplate/**File:random.h*Version:1.0*LastmodifiedonFriJul2216:44:361994byeroberts*-----------------------------------------------------*Thisinterfaceprovi......
  • Programming abstractions in C阅读笔记:p107-p110
    《ProgrammingAbstractionsInC》学习第46天,p107-p110,3.1小节——“Theconceptofinterface”,总结如下:一、技术总结1.clientp108,调用library的program称为client。2.interfacep108,"Todoso,thechapterfocusesontheboundarybetweenalibraryanditsclients,wh......