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

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

?? chapter6.html

?? WRITING BUG-FREE C CODE.
?? HTML
?? 第 1 頁 / 共 3 頁
字號:
<html><head><title>Writing Bug-Free C Code: Designing Modules</title></head><body><center><font size="+3">Chapter 6: Designing Modules</font><br><a href="index.html">Writing Bug-Free C Code</a><br></center><br><center><table><tr><td valign=top><small><a href="#smallvslarge">6.1 Small versus Large Projects</a><br><a href="#thekey">6.2 The Key</a><br><a href="#whatis">6.3 What Is a Module?</a><br><a href="#designing">6.4 Designing a Class Implementation Module</a><br><small></td><td width=30>&nbsp;</td><td valign=top><small><a href="#usemodel">6.5 The USE_* Include File Model</a><br><a href="#coding">6.6 Coding the Module</a><br><a href="#sample">6.7 A Sample Module</a><br><a href="#summary">6.8 Chapter Summary</a><br></small></td></tr></table></center><br><br>What is a module?  Is it simply a source file that contains functions?  In a high-level sense, yes, but it is also much more.  Anyone can write some functions, place them in a file and call them a module.  For me, a module is the result of applying a well-founded set of techniques to solving a problem.<br><a name="smallvslarge"><br></a><big><b>6.1 Small versus Large Projects</b></big> <br><br>How are small projects usually designed?  It has been my experience that small projects are usually written by one person over the course of several hours to several days.  In this environment, there is no real concern given to splitting the project into several well-defined source files.  More than likely, the small project ends up simply being one source file. <br><br>For small projects, this one source file design works quite well, but what about large projects with hundreds of thousands of lines of code and hundreds of source files? <br><br>The challenge in working on any project is applying a well founded set of techniques from day one, because every project, no matter how big it is today, started out as a small project.<br><a name="thekey"><br></a><big><b>6.2 The Key</b></big> <br><br>The key to successfully coding a hierarchy of modules is that you must always code what to do, not how to do it. <br><br>In other words, implement the solution to a problem once, not multiple times.  A simple, but effective example is copying a string from one location to another.  Do you use while (*pDst++=*pSrc++); or do you use strcpy(pDst, pSrc);?  This may seem like an absurd example, but study it carefully.  The while loop is specifying how to copy a string from one location to another, while strcpy() is specifying what to do, leaving the how to strcpy().   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   The key is to always code <i>what</i> to do, not <i>how</i> to do it.   </tr></td></table></blockquote>This point is so key that I will repeat it.  The while loop is specifying how to copy a string from one location to another, while the strcpy() is specifying what to do, leaving the how to strcpy(). <br><br>I chose strcpy() on purpose because I do not know anyone who would argue for using the while loop instead of strcpy().  Why is the choice of which one to use so obvious? <br><br>More than likely, some of the code you have written contains code fragments that specify how to do something instead of specifying what to do. <br><br><b>6.2.1 An Example</b> <br><br>Let me give you a prime example that comes straight from programming in a GUI environment.  In a dialog box, there exists an edit control that contains text that the user can edit, but suppose you want to limit the number of characters that the user can type.  How do you do it?  In Microsoft Windows, you send a message to the edit control, informing it of the text limit.  This is done with the SendDlgItemMessage() function and the EM_LIMITTEXT message. <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre><b>Limiting text size in a Microsoft Windows edit control</b>SendDlgItemMessage( hDlg, nID, EM_LIMITTEXT, wSize, 0L );</pre></tr></td></table> <br>So, whenever you want to limit the size of an edit control, you call SendDlgItemMessage(), right?  I do not think so! <br><br>The problem is that by calling SendDlgItemMessage() directly, you are specifying how to limit the text size. <br><br>The solution is to code a new function, let's call it EmLimitText(), that calls SendDlgItemMessage().  Whenever you want to limit the text size of an edit control, you call EmLimitText() instead of SendDlgItemMessage(). <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre><b>EmLimitText function</b>void APIENTRY EmLimitText( HWND hDlg, int nID, WORD wSize ){    SendDlgItemMessage( hDlg, nID, EM_LIMITTEXT, wSize, 0L );} /* EmLimitText */</pre></tr></td></table> <br>By doing this, you now have the basis for an entire module.  For all messages that can be sent to edit controls, provide code wrappers that specify what to do and let the functions call SendDlgItemMessage(), which specify how to do it. <br><br><b>6.2.2 Another Example</b> <br><br>The class methodology is a prime example of specifying what to do and not how to do it.  Consider what coding is like without the class methodology.  It is up to each and every module to directly access a data object to perform whatever action is necessary.  By directly accessing the object, the code is specifying how to perform the action. <br><br>The class methodology forces modules to use method functions to perform an action upon the object.  The code is specifying what do to, leaving the how up to the method function. <br><br><b>6.2.3 The Advantages</b> <br><br>By far the single biggest advantage of using the technique of specifying what to do instead of how to do it is that it allows you to radically change the how (the implementation), without having to change the what (the function calls). <br><br>Another advantage of this technique is that it allows you to make changes to the implementation and recompile only one source file.  Since the function interface remains the same, no other source files have to be recompiled. <br><br>The turnaround time in making a change and testing it are also dramatically reduced because only one source file needs to be recompiled instead of tens or hundreds. <br><br>Another benefit of this technique is that code size is reduced.  Instead of repeatedly spelling out in code how to do something, you are now making a function call, which in most cases reduces the code size. <br><br><b>6.2.4 The Goal</b> <br><br>The goal in using this technique in your programs is to reach the point at which implementing new functionality is simply a matter of making a few function calls.  This is obviously ideal and does not happen all the time, but the more this technique is used, the more frequently it starts to happen. <br><br><b>6.2.5 Conclusion</b> <br><br>The key to this technique is to always code what to do, not how to do it.  In other words, you never want to reinvent the wheel.  Instead, implement it once and be done with it!  Be careful, however, that you design a solid interface that stands up to the test of time.  You do not want to change the interface later, since this requires all modules that use the interface to change as well. <br><br>This technique is easy to use when the implementation of something is hundreds of lines long and the obvious choice is to make a function call.  However, the real power of this technique comes when it is used extensively in a project, even for implementations that are several lines to one line long.  It takes a lot of discipline to use the technique in these cases, but the payoff comes the next time when all you need is a function call.<br><a name="whatis"><br></a><big><b>6.3 What Is a Module?</b></big> <br><br>A module is a source file with well-defined entry points, or method functions (methods), that can be called by other modules.  It is the result of applying a well-founded set of techniques to solving a problem.  There are primarily two types of modules:  code wrapper modules and class implementation modules.  Some code wrapper modules also implement a class and hence are considered class implementation modules as well. <br><br>Code wrapper modules provide functions that are primarily code wrappers.  Most code wrapper functions are independent and stand on their own.  Because of this, they can be moved to another module without any compilation problems.  Functions are grouped in a module because they provide similar functionality. <br><br>An example is the heap manager module.  It sits on top of C's memory allocation routines to provide a cleaner, more robust interface into the system. <br><br>Another example is a module that provides code wrappers around all messages that can be sent to edit controls in a GUI environment.  An example is using EmLimitText() instead of calling SendDlgItemMessage() directly.<br><a name="designing"><br></a><big><b>6.4 Designing a Class Implementation Module</b></big> <br><br>Class implementation modules provide functions that implement a class.  The functions must be present in the module for a successful compilation.  Functions are grouped in a module because the functions, as a whole, implement the class. <br><br>An example of a class implementation module is the random number generator discussed in <a href="chapter4.html#randomexample">&sect;4.7</a>. <br><br><b>6.4.1 The Interface or API</b> <br><br>By far the toughest and most important part of designing a module is designing the API (Application Programmer's Interface) to the new module. <br><br>Once an API is chosen and implemented, it is not likely to change much over time.  This is because as a module gets used more and more by other modules, a change in the API is expensive in terms of the time and effort required to implement and debug the change.   <blockquote><table bgcolor="#E0E0E0" border=1 cellpadding=2 cellspacing=0><tr><td>   An API must be designed right the first time because changes to an   API are costly.   </tr></td></table></blockquote>The first step in creating a new class implementation module API is deciding upon a handle name that is used to refer to objects created by the API.  The handle name must begin with an H and be in uppercase.  A name is chosen so that it is obvious, unique, relatively short and has a good mixed case name, usually spelled the same as the handle.  You also need a module name so that functions of the module follow the module/verb/noun naming convention. <br><br>In the random number generator, HRAND was chosen as the handle name.  It is pretty obvious, unique from all other handle names and relatively short.  The variable name used to refer to objects of the class is hRand.  Rand is the module name used to prefix method functions, as in RandCreate() and RandDestroy(). <br><br>Suppose we are creating a class module that provides a code wrapper around opening, reading, writing and closing operating system files.  In this case, the code wrapper module is a class implementation module.  I would choose a handle name of HDOSFH (Handle to the DOS File Handle), a variable name of hDosFh, a module name of Dos and method function names of DosOpenFile(), DosRead(), DosWrite() and DosCloseFile(). <br><br>All modules that implement a class have at least two method functions: one method function that creates the object (for example, RandCreate() and DosOpenFile()) and another method function that destroys the created object (for example, RandDestroy() and DosCloseFile()). <br><br>An important concept of class modules is that the method functions act upon dynamically allocated objects, objects that are created and destroyed using method functions.  The method functions do not act upon static objects. <br><br><b>6.4.2 An Interface Specification Template</b> <br><br>The interface specification for new class modules follows a general template.  First of all there is a NEWHANDLE(HOBJ) declaration that is at the top of a global include file.  This adds a new type checkable data type, named HOBJ, into the system.  It is declared near the top of the include file, next to all other NEWHANDLE() declarations, so that, if needed, HOBJ may be used in the prototypes of other USE_ sections. <br><br>The NEWHANDLE(HOBJ) declaration is not included in the USE_HOBJ section because to use only the HOBJ data type in other USE_ prototype sections would require the entire USE_HOBJ section to be included first.  Why include the entire section when all that is needed is access to NEWHANDLE(HOBJ)? <br><br><table bgcolor="#CCCCEE" cellpadding=0 cellspacing=0><tr><td><pre><b>Template interface for a new module</b>NEWHANDLE(HOBJ);...#ifdef USE_HOBJ/*-------------------------------------------------------------- * *  Short one line description of module * *-------------------------------------------------------------*/EXTERNC HOBJ APIENTRY ObjCreate      ( arguments );EXTERNC type APIENTRY ObjMethodName1 ( HOBJ, arguments );EXTERNC type APIENTRY ObjMethodName2 ( HOBJ, arguments );...EXTERNC type APIENTRY ObjMethodNameN ( HOBJ, arguments );EXTERNC HOBJ APIENTRY ObjDestroy     ( HOBJ );#endif</pre></tr></td></table> <br><br>The function prototypes for the method functions of the class appear later in the include file.  A create method that returns a handle to the created object is present along with all other method functions for the class (which expect the object handle as the first argument).  By convention, NULL is always returned by the ObjDestroy() method.  The arguments and return type of all other method functions depend upon the class implementation.  Usage of APIENTRY is discussed later in this chapter. <br><br>Notice that the module prototypes are enclosed within an #ifdef / #endif section.  This implements the USE_* include file model, which is discussed next.<br><a name="usemodel"><br></a><big><b>6.5 The USE_* Include File Model</b></big> <br><br>When I first started coding in C, I followed the traditional technique of placing data declarations and function prototypes in a separate include file and explicitly including it in whatever source files needed access to the information.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲第一精品在线| 日韩不卡一区二区| 欧美一区2区视频在线观看| 日韩中文字幕麻豆| 国产精品久久久久久久久晋中 | 久久精品亚洲精品国产欧美kt∨| 99久久精品国产精品久久| 婷婷国产v国产偷v亚洲高清| 最新高清无码专区| 久久亚洲免费视频| 欧美精品少妇一区二区三区| 成人高清视频在线观看| 六月丁香婷婷久久| 亚洲电影一级片| 亚洲丝袜美腿综合| 国产欧美一区二区精品久导航| 日韩一级高清毛片| 欧美在线观看视频一区二区三区| 国产成人精品三级麻豆| 九色综合狠狠综合久久| 五月激情六月综合| 夜夜精品视频一区二区 | 欧美伊人久久大香线蕉综合69| 国产精品亚洲一区二区三区妖精| 五月天亚洲婷婷| 天堂av在线一区| 一区二区久久久久| 亚洲黄色av一区| 亚洲天堂2014| 日韩毛片在线免费观看| 国产精品系列在线| 国产精品美女一区二区三区| 国产亚洲自拍一区| 久久网站最新地址| 精品动漫一区二区三区在线观看 | 亚洲欧洲日韩综合一区二区| 久久久美女毛片| 精品国产麻豆免费人成网站| 欧美电视剧在线观看完整版| 欧美一区二区视频在线观看2022| 欧美一区二区高清| 欧美成人官网二区| 亚洲精品在线观看网站| 日韩精品一区二区三区视频| 精品成人a区在线观看| 欧美成人精品高清在线播放| 2022国产精品视频| 久久久久久久电影| 日本一区二区电影| 亚洲婷婷在线视频| 亚洲高清不卡在线观看| 天涯成人国产亚洲精品一区av| 热久久一区二区| 国产麻豆精品在线观看| www.日韩大片| 在线亚洲免费视频| 91精品国产乱| 国产无人区一区二区三区| 欧美激情艳妇裸体舞| 综合电影一区二区三区 | 日本最新不卡在线| 精品无码三级在线观看视频 | 国产精品亚洲综合一区在线观看| 成人动漫av在线| 欧美吻胸吃奶大尺度电影| 欧美一二三区在线观看| 久久先锋资源网| 伊人婷婷欧美激情| 免费高清在线视频一区·| 粉嫩aⅴ一区二区三区四区五区| 91捆绑美女网站| 欧美精品粉嫩高潮一区二区| 精品久久国产老人久久综合| 中文字幕国产一区二区| 亚洲成人动漫av| 国产一区亚洲一区| 色综合久久99| 亚洲精品一区二区三区蜜桃下载 | 粉嫩aⅴ一区二区三区四区五区| 色一区在线观看| 日韩欧美色综合网站| 欧美国产乱子伦| 五月天亚洲精品| 国产成人精品免费视频网站| 欧美三区在线观看| 久久精品视频在线免费观看| 亚洲小少妇裸体bbw| 国产精品18久久久久久久久| 欧美三级一区二区| 国产精品黄色在线观看| 日韩不卡一区二区| 91亚洲国产成人精品一区二区三 | 91免费在线看| 精品国产露脸精彩对白| 中文字幕制服丝袜成人av| 免费观看日韩电影| 色综合激情久久| 国产校园另类小说区| 午夜久久久久久久久久一区二区| 成人午夜精品在线| 日韩一区二区三区电影在线观看 | 亚洲欧美日韩国产成人精品影院| 亚洲不卡在线观看| 99视频在线精品| 久久女同性恋中文字幕| 日韩专区在线视频| 日本高清视频一区二区| 国产人成一区二区三区影院| 欧美aⅴ一区二区三区视频| 欧美在线短视频| 中文字幕在线不卡| 国产馆精品极品| 精品少妇一区二区| 日本亚洲视频在线| 欧美日韩成人综合天天影院| 亚洲精品国产精华液| 成人听书哪个软件好| 久久久高清一区二区三区| 精品制服美女丁香| 欧美另类z0zxhd电影| 亚洲自拍都市欧美小说| 91在线一区二区| 国产精品久久久久久久第一福利 | 亚洲三级久久久| 成人免费观看男女羞羞视频| 久久久高清一区二区三区| 久久国产免费看| 日韩精品专区在线影院重磅| 青青草原综合久久大伊人精品| 欧美日韩午夜在线| 亚洲一区在线播放| 欧美在线啊v一区| 夜夜亚洲天天久久| 欧美视频日韩视频| 五月天一区二区三区| 在线综合+亚洲+欧美中文字幕| 亚洲成av人片在线| 欧美日韩精品欧美日韩精品一 | 青娱乐精品视频在线| 日韩一区二区在线看片| 日本aⅴ精品一区二区三区| 6080亚洲精品一区二区| 蜜桃精品视频在线| 精品对白一区国产伦| 国产精品一区二区果冻传媒| 日本一区二区三区高清不卡| 粉嫩欧美一区二区三区高清影视| 中文字幕亚洲成人| 色婷婷亚洲精品| 午夜成人免费视频| 欧美一区二区成人| 国产成人免费视频网站高清观看视频| 亚洲精品一区二区精华| 国产一区二区三区观看| 国产精品色哟哟| 色综合欧美在线| 秋霞午夜鲁丝一区二区老狼| 久久精品水蜜桃av综合天堂| 北岛玲一区二区三区四区| 亚洲精品免费播放| 欧美日韩一区在线| 国产在线精品一区二区不卡了| 国产欧美日韩视频在线观看| 不卡电影一区二区三区| 夜夜揉揉日日人人青青一国产精品| 欧美日韩国产欧美日美国产精品| 久久国产精品72免费观看| 国产精品色在线观看| 欧美在线观看一二区| 精品在线视频一区| 亚洲精品免费视频| 精品国产在天天线2019| 成年人国产精品| 天天影视网天天综合色在线播放 | 成人午夜激情在线| 亚洲chinese男男1069| 久久综合久色欧美综合狠狠| 99精品视频一区二区| 日韩精品乱码免费| 国产精品伦理一区二区| 欧美日韩成人在线| 成人黄色av网站在线| 天堂久久久久va久久久久| 国产日韩欧美高清| 91精品一区二区三区久久久久久 | www.一区二区| 午夜免费久久看| 国产女人水真多18毛片18精品视频| 日本电影亚洲天堂一区| 国产一区视频网站| 天天操天天色综合| 亚洲免费毛片网站| 久久免费视频色| 91精品国产一区二区三区 | 色婷婷综合久色| 国产凹凸在线观看一区二区| 日韩综合小视频| 亚洲自拍偷拍九九九| 中文字幕一区二区三区色视频| 日韩欧美在线影院|