亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chapter3.html

?? WRITING BUG-FREE C CODE.
?? HTML
?? 第 1 頁 / 共 3 頁
字號:
<html><head><title>Writing Bug-Free C Code: Rock-Solid Base</title></head><body><center><font size="+3">Chapter 3: Rock-Solid Base</font><br><a href="index.html">Writing Bug-Free C Code</a><br></center><br><center><table><tr><td valign=top><small><a href="#systembugs">3.1 System Functions Contain Bugs</a><br><a href="#usemacros">3.2 Using Macros to Aid Porting</a><br><a href="#winassert">3.3 Using WinAssert() Statements</a><br><small></td><td width=30>&nbsp;</td><td valign=top><small><a href="#naming">3.4 Naming Conventions</a><br><a href="#summary">3.5 Chapter Summary</a><br></small></td></tr></table></center><br><br>Would you build a skyscraper without a proper, solid foundation?  Of course not.  Would you build a large application without a rock-solid base system?  I wouldn't, and yet I get the feeling that this is happening every day.  Do you consider the standard C library to be a rock-solid base?  Before you answer this, I need to clarify what I consider to be rock-solid. <br><br>A rock-solid function must first of all be bug-free itself.  The function must provide a clean, intuitive interface.  What hope would you ever have if you were constantly making mistakes in how a function is called?  Function names must clearly state what the function does.  What good is a function named DoIt()?  The function must detect and report invalid function arguments.  The function should be fault-tolerant.  The program you are working on should not crash simply because you called a function incorrectly.   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   Before you can write bug-free code, you must have   a bug-free, rock-solid base.   </tr></td></table></blockquote>Do you now consider the standard C library to be a rock-solid base?  Many functions are, but many functions are not.  Consider the heap management routines in the C library, specifically, the free() function.  The free() function deallocates a block of memory that was previously allocated through the malloc() function call. <br><br>What happens when you pass free() a completely random value, or a value that you have already previously passed to free()?  Your program may bomb immediately.  If it doesn't, the heap may be corrupted.  If it isn't, some memory may have been overwritten.  The point is that not all C library functions are rock-solid.  Why not first code a layer on top of the system base that is rock-solid?   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   Not all C library functions are rock-solid.  A layer that is   rock-solid needs to be coded.   </tr></td></table></blockquote>As you code your program, you need to consider the current program as it stands as the base for whatever new features you are putting in.  Once done, this is the new base for the next set of features.  As you code, make sure that the current base is rock-solid; that it is fault-tolerant and that it catches incorrect usage of functions.  If the base is not rock-solid, you need to make it rock-solid.<br><a name="systembugs"><br></a><big><b>3.1 System Functions Contain Bugs</b></big> <br><br>Your underlying operating system or development environment has bugs in it.  Since there is no such thing as a completely bug-free system, try to find out as much as you can about the environment you are working on.  Try to obtain bug lists if they are available. <br><br><table bgcolor="#F0F0F0"><tr><td><img src="./windows.gif"> Microsoft has recently started the Microsoft Developer Network.  It is a program that is intended to get as much information and technical resources as possible into the hands of developers.  The program distributes information in the form of a CD and a Windows-based browser.  I highly recommend this program to developers. The Microsoft Developer Network can be reached through the Internet at <a href="http://msdn.microsoft.com">http://msdn.microsoft.com</a> </td></tr></table> <br><table bgcolor="#F0F0F0"><tr><td><img src="./windows.gif"> <b>3.1.1 A MS-DOS Bug</b> <br><br>An example of a bug that was found in the MS-DOS operating system involves lost clusters.  It was detected by an <a href="chapter7.html#automatedtesting">automated testing procedure &sect;7.24</a>. As the automated testing function would run, invariably it would eventually run out of disk space, but the function never created any file large enough to even come close to running out of disk space.  As it turned out, disk clusters were being lost by the operating system on a regular basis and eventually the disk would run out of free clusters.  The only way to recover the lost clusters was to run the CHKDSK program provided by the operating system. <br><br>This bug is a confirmed bug in MS-DOS 3.2 and MS-DOS 3.3, the only versions available when the bug was discovered.  The bug does not exist in MS-DOS 5.0 and later versions. <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre><b>C program that shows MS-DOS version 3.3 lost cluster bug</b>#include &lt;fcntl.h&gt;#include &lt;sys\types.h&gt;#include &lt;sys\stat.h&gt;#include &lt;io.h&gt;#include &lt;stdio.h&gt;int main(void){    char c;    int fh = creat( "it.tmp", S_IREAD|S_IWRITE );    lseek( fh, 81920, SEEK_SET );    write( fh, &c, 1 );    chsize( fh, 81920 );    lseek( fh, 122880, SEEK_SET );    write( fh, &c, 1 );    close( fh );    return 0;} /* main */</pre></tr></td></table> <br>Running this program repeatedly under MS-DOS 3.2 or MS-DOS 3.3 will cause the lost cluster bug.  Run CHKDSK to recover the lost clusters.</td></tr></table><br><table bgcolor="#F0F0F0"><tr><td><img src="./windows.gif"> <b>3.1.2 Windows Bugs</b> <br><br>As any early Windows developer will tell you, Windows was a buggy operating system.  Over the course of five years, I accumulated over six three-ring binders full of correspondence with Microsoft support concerning bugs in the Windows system. <br><br>With the introduction of Windows 3.0, I noticed a significant drop in the number of problems that I was reporting.  I attribute this reduction to the fact that Windows 3.0 was a protected-mode operating system (previously it was not).  Many types of errors cause a CPU fault and the error can be pinpointed immediately.  However, the Windows 3.0 system was still a little shaky when it came to DOS boxes, the emulation of a MS-DOS PC in a Windows window. <br><br>With the introduction of Windows 3.1, the number of bugs that I report has dropped dramatically.  I consider Windows 3.1 to be a stable operating environment.  In fact, on my development machine, I stay in Windows all day and use DOS boxes to run my MS-DOS applications.  My machine may crash once a week.  Not too bad, but still room for improvement. <br><br>However, there is a particularly nasty bug I have found that still exists in Windows 3.1.  Luckily, the likelihood that you will ever encounter the bug is almost nil.  The bug is that sometimes the Windows multitasker does not switch to the correct PSP when a Windows application performs disk I/O.  What this means is that a file handle that should be correct is not, because the program is in the open file context of another application! <br><br>A little background may be needed to explain why this can even occur.  When Windows multitasks applications, it has to keep a tremendous amount of information around for each application.  One piece of that information is the open files context.  In order to significantly speed up task switching in Windows, the open files context is not switched until the task actually performs an operation that requires the open files context.  Reading and writing a disk file is an example of an operation that would cause a true open files context switch.  Since most applications rarely perform disk I/O relative to the amount of CPU time they need, this delayed context switch of the open files context speeds up multitasking. <br><br>The bug occurs when, in the course of multitasking applications, the Windows kernel incorrectly thinks that it is truly in the open files context of the currently running application, when, in fact, it is in the open files context of another application.  Microsoft has been slow to fix this problem since the circumstances that cause the bug to occur are extreme. <br><br>The only reason I found this bug in the first place is because of an automated testing procedure I used to test the correctness of a new module.  This procedure caused almost continuous I/O to occur and every once in a great while, an I/O would fail under low memory conditions. <br><br>A Windows 3.1 bug.  There is another bug that I found that anyone can reproduce easily on any Windows 3.1 machine.  First, run the standard Notepad application.  Go into the file open dialog and click with the mouse on the OK button.  Now press and hold down the space bar.  While continuing to hold down the space bar, press the ESC key.  This causes a General Protection Fault.  The problem has to do with the dialog manager inside the Windows kernel.  The fault occurs because both an IDOK and an IDCANCEL are being sent to the dialog callback procedure when in reality, only one message should be sent.  This is a problem with all dialogs in all applications.  However, the application may or may not fault.  It just depends upon how the application was written to respond to the IDOK and IDCANCEL messages.  This bug is fixed in Windows 3.11.</td></tr></table><br><b>3.1.3 What to Do</b> <br><br>The point in demonstrating to you that bugs do exist in MS-DOS and Windows is to emphasize that sometimes even system level functions fail.  Code that you think never fails is bound to fail sometime. <br><br>My reaction to having system level functions fail me has been to provide another layer of code between my application code and the system level functions that checks for assumptions that I am making.  At some point, you write code that makes an assumption.  Consider the following code. <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre><b>Code with an assumption</b>int fh = open(....);if (fh!=-1) {    close(fh);    }</pre></tr></td></table> <br>Do you see what the assumption is?  The assumption being made in this code is that the close() function never fails.  Well then, why not assert this?  The close() returns zero for success, otherwise non-zero for failure.   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   Provide a code wrapper around all system calls.   </tr></td></table></blockquote>The best solution is to provide a wrapper function around each and every system call.  Assert any assumptions that are being made within this wrapper function.  Placing the assert in the wrapper function once instead of every place it is being called is a lot less error prone.<br><a name="usemacros"><br></a><big><b>3.2 Using Macros to Aid Porting</b></big> <br><br>With all the different machine architectures that are in use today, how in the world do you write code so that it can be ported easily?  C provides an excellent mechanism for conditional compilation, but this is only a small part of the solution. <br><br>How do you handle segmented versus non-segmented architectures?  What about C and C++?  There are slight differences between the two languages. <br><br>One solution that works really well is to abstract out the interdependencies between the environments into a set of macros so that the code base does not have to change.   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   Use macros as an aid to porting so that your code base does not   change at all.   </tr></td></table></blockquote><a name="segmentedflat"></a><b>3.2.1 Segmented/Flat Architecture Macros</b> <br><br>A number of #defines that provide a basis for further development are as follows. <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷精品久久二区二区蜜臀av| 蜜臀91精品一区二区三区| 久久精品一区二区三区四区| 欧美一卡2卡3卡4卡| 91精品国产美女浴室洗澡无遮挡| 欧美日本一区二区| 91精品中文字幕一区二区三区| 欧美日韩午夜影院| 欧美高清你懂得| 69久久99精品久久久久婷婷| 欧美一级日韩免费不卡| 日韩片之四级片| 久久久久久久一区| 国产精品人妖ts系列视频| 亚洲乱码精品一二三四区日韩在线| 综合网在线视频| 亚洲激情中文1区| 日本女人一区二区三区| 韩国精品一区二区| 粉嫩av亚洲一区二区图片| 91伊人久久大香线蕉| 欧美色手机在线观看| 日韩欧美黄色影院| 欧美国产精品专区| 亚洲国产精品一区二区久久恐怖片| 无吗不卡中文字幕| 国产一区视频导航| 色综合中文字幕| 国内久久婷婷综合| 成人精品国产福利| 色88888久久久久久影院按摩| 欧美精品日韩精品| 国产女主播一区| 亚洲成人免费观看| 岛国av在线一区| 欧美丰满一区二区免费视频| 久久精品欧美一区二区三区不卡| 亚洲欧美国产77777| 麻豆视频观看网址久久| 99re在线视频这里只有精品| 日韩欧美精品在线| 亚洲国产一区二区三区| 色狠狠av一区二区三区| 欧美高清dvd| 亚洲免费在线观看视频| 免费日本视频一区| 欧美在线你懂得| 国产视频一区二区三区在线观看| 香蕉久久夜色精品国产使用方法 | 国产精品二三区| 日韩av一二三| 在线亚洲高清视频| 国产网红主播福利一区二区| 欧美a一区二区| 91麻豆自制传媒国产之光| 日韩欧美国产1| 舔着乳尖日韩一区| 一本在线高清不卡dvd| 久久久久久久久一| 久久精品国产**网站演员| 欧美性生活大片视频| 亚洲欧洲精品成人久久奇米网 | 久久久精品综合| 免费观看在线综合| 欧美日韩五月天| 亚洲女与黑人做爰| 成人综合激情网| 国产婷婷色一区二区三区四区| 毛片一区二区三区| 91精品国产综合久久久久久久久久 | 日韩成人av影视| 欧美三级在线看| 亚洲国产成人精品视频| 欧美色区777第一页| 亚洲一线二线三线视频| 欧美色倩网站大全免费| 午夜精品成人在线| 欧美剧情片在线观看| 婷婷国产在线综合| 欧美日韩国产a| 日韩精品一级中文字幕精品视频免费观看 | 99久久99久久精品国产片果冻| 国产三级久久久| 成人av综合在线| 国产精品福利一区二区| 91亚洲精品乱码久久久久久蜜桃| 国产精品国产三级国产aⅴ原创| av中文字幕不卡| 亚洲图片欧美综合| 欧美一卡二卡在线观看| 国产精品亚洲一区二区三区妖精 | 天天综合日日夜夜精品| 精品免费99久久| 成人av免费在线观看| 亚洲激情五月婷婷| 欧美日本在线视频| 国产精品18久久久久久久久久久久| 日本一区二区三区在线不卡| 91香蕉视频污| 午夜日韩在线观看| 久久精品这里都是精品| 色偷偷久久人人79超碰人人澡 | 日韩女优电影在线观看| 成人av综合在线| 日韩国产欧美三级| 国产精品伦一区| 欧美午夜精品理论片a级按摩| 天天爽夜夜爽夜夜爽精品视频| 日韩午夜av电影| 99久久精品99国产精品| 日本不卡的三区四区五区| 国产日韩欧美综合一区| 91美女片黄在线观看| 日本成人在线网站| 亚洲视频 欧洲视频| 日韩丝袜美女视频| 一本一道久久a久久精品综合蜜臀| 麻豆成人综合网| 亚洲精品国产无天堂网2021| 欧美精品一区二区三区在线播放| 成人91在线观看| 日韩av一二三| 一区二区免费在线| 国产精品网站在线播放| 日韩欧美一卡二卡| 色视频成人在线观看免| 国产v综合v亚洲欧| 国精产品一区一区三区mba视频| 玉足女爽爽91| 成人免费在线视频| 久久久亚洲午夜电影| 欧美日韩国产小视频| 色88888久久久久久影院按摩| 国产精一区二区三区| 日本vs亚洲vs韩国一区三区二区| 一区二区三区成人| 亚洲欧美日韩小说| 国产精品国产馆在线真实露脸| 26uuu亚洲综合色欧美| 欧美一区二区三区免费视频| 色老汉一区二区三区| 色一情一乱一乱一91av| 成人av动漫网站| 国产69精品久久久久毛片| 蜜乳av一区二区三区| 五月天丁香久久| 天堂精品中文字幕在线| 亚洲午夜av在线| 亚洲成av人片在线观看无码| 亚洲国产精品视频| 亚洲国产成人av网| 午夜视频在线观看一区二区三区 | 欧美tk丨vk视频| 91精品国产综合久久香蕉的特点| 欧美美女直播网站| 91精品国产高清一区二区三区 | 精品国产伦一区二区三区免费| 欧美一级一区二区| 精品国产区一区| 久久久精品日韩欧美| 中文字幕在线不卡一区二区三区| 国产精品美女久久久久久久久久久 | 欧美视频在线一区二区三区 | 91亚洲男人天堂| 91久久国产最好的精华液| 欧美在线三级电影| 欧美精品精品一区| 久久一区二区三区四区| 国产精品久久看| 一区二区三区精品视频| 视频一区二区国产| 狠狠色狠狠色合久久伊人| 国产精品白丝av| 色天使色偷偷av一区二区| 欧美日韩一区国产| 精品国产网站在线观看| 国产精品久久午夜夜伦鲁鲁| 亚洲综合在线观看视频| 日本美女视频一区二区| 国产福利91精品一区| 欧美最猛性xxxxx直播| 日韩欧美另类在线| 国产精品福利电影一区二区三区四区| 曰韩精品一区二区| 极品少妇一区二区三区精品视频| 成人污污视频在线观看| 欧美无人高清视频在线观看| 久久综合色天天久久综合图片| 综合电影一区二区三区| 日本成人在线看| 99精品1区2区| 精品国产免费人成在线观看| 亚洲精品自拍动漫在线| 免费黄网站欧美| 色综合久久久网| 国产婷婷一区二区| 奇米777欧美一区二区| 色综合久久久久综合体| 26uuu国产日韩综合| 亚洲福利电影网|