<?xml version="1.0" encoding="gbk"?> <rss version="2.0"><channel> <title>定阅帖子更新</title> <link>http://www.broadkey.com.cn/XML.ASP</link><description>TEAM Board - 科伟奇电子</description> <copyright>TEAM 2.0.5 Release</copyright><generator>TEAM Board by TEAM5.Cn Studio</generator> <ttl>30</ttl><item><link>http://www.broadkey.com.cn/Thread.asp?tid=393 </link><title>CodeWarrior&amp;nbsp;使用教程</title><author>美好人生</author><pubDate>2009/12/14 9:30:31</pubDate><description><![CDATA[<div style="opacity: 1" id="ctl00_ctl00_SkinBody_Content_ContentControl_ctl00_Digg2_display">
<p style="line-height: 0px; clear: both">&nbsp;</p>
<p>&nbsp;</p>
</div>
<div>
<div align="center"><font size="3"><strong>第一课认识 CodeWarrior</strong> <span style="font-size: 10pt">Translated from </span></font><strong><span style="font-size: 10pt">CodeWarriorU.COM</span></strong></div>
<div><strong><span style="color: black">CodeWarrior </span></strong><strong><span style="color: black">能做些什么</span></strong><strong><span style="color: black">?</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">当你知道自己能写更好的程序时，你一定不会再使用别人开发的应用程序。但是常常会发生这种情况，就是当你写了无数行代码后，却找不到使得整个程序出错的那一行代码，导致根本没法编译和链接整个程序。这可能更令人灰心丧气。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">本文将告诉你如何使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">这一工具解决上述问题。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">从现在开始，我们将集中精力学习如何在 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">中使用 </span><span style="font-size: 10pt">C/C++ </span><span style="font-size: 10pt">进行编程。为了学习本课程，你必须已经能够比较熟练地使用上述两种语言之一。</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">也可以支持 </span><span style="font-size: 10pt">Java </span><span style="font-size: 10pt">开发，但那是另一门课程的内容。本课程仅限于在 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">平台上使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">进行的开发。一旦你精通了 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编程后，你可以试试在其它平台上使用 </span><span style="font-size: 10pt">CodeWarrior</span><span style="font-size: 10pt">。本文中讨论过的大部分内容都可以应用到开发 </span><span style="font-size: 10pt">Mac </span><span style="font-size: 10pt">应用程序中。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior </span><span style="font-size: 10pt">能够自动地检查代码中的明显错误，它通过一个集成的调试器和编辑器来扫描你的代码，以找到并减少明显的错误，然后编译并链接程序以便计算机能够理解并执行你的程序。你所使用过的每个应用程序都经过了使用象 </span><span style="font-size: 10pt">CodeWorrior </span><span style="font-size: 10pt">这样的开发工具进行编码、编译、编辑、链接和调试的过程。现在你在我们的指导下，自己也可以去做这些工作了。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">你可以使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">来编写你能够想象得到的任何一种类型的程序。如果你是一个初学者，你可以选择编写一个应用程序</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">比如一个可执行程序</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，比如象微软公司的文本编辑器 </span><span style="font-size: 10pt">WordPad </span><span style="font-size: 10pt">这样的应用程序。</span></div>
<div><font size="3"><strong><span style="color: black">CodeWarrior </span></strong><strong><span style="color: black">入门</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior </span><span style="font-size: 10pt">是一个复杂的应用程序，你必须花点时间来了解它的各种各样的组件和功能。第一课将讲述 </span><span style="font-size: 10pt">CodeWarrior IDE </span><span style="font-size: 10pt">的安装。我们将学习菜单、窗口和其它的一些方面。建议你最好一边学习本课程，一边学习使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的集成开发环境。我们从运行 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">开始，如果你按照默认方式安装的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">软件，那么在 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">的桌面上将会有一个该软件的快捷方式图标。双击该图标启动 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的集成开发环境。如果在 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">桌面上没有这个快捷图标</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">这种情况经常发生</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，你可以在 </span><span style="font-size: 10pt">C:\Program Files\Metrowerks\CodeWarrior\Bin </span><span style="font-size: 10pt">中找到 </span><span style="font-size: 10pt">IDE.exe </span><span style="font-size: 10pt">文件，然后运行它。</span></div>
<div><strong><span style="font-size: 10pt">工具条</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">启动 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">后，你将会看到，在屏幕上方的菜单下面有一个工具条。这个工具条</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">见图</span><span style="font-size: 10pt">1-1)</span><span style="font-size: 10pt">包含了一些常用菜单项的快捷方式。在后面的章节中，你将学到如何设置这个工具条，甚至是整个 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">环境。现在，你应记住，这个工具条用于快捷使用 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">中的功能。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">1-1: CodeWarrior IDE </span></em><em><span style="font-size: 7.5pt">的工具条</span></em></div>
<div><strong><span style="font-size: 10pt">文件菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior IDE </span><span style="font-size: 10pt">的菜单是按照标准方式设置的。其中的文件菜单用于处理和文件相关的一些操作，比如创建、打开、保存和打印等等。</span></div>
<div><strong><span style="font-size: 10pt">编辑菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior </span><span style="font-size: 10pt">的编辑菜单和其它的</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">应用程序也很相像。其中包括了剪切、复制和粘贴等操作，以及其它一些使得程序员能够更方便地管理源码版面布局的选项。在编辑菜单中还有一个</span><span style="font-size: 10pt"> Preferences </span><span style="font-size: 10pt">项，我们在这一课的后面将提到它。</span></div>
<div><strong><span style="font-size: 10pt">查看菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">查看菜单</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">图</span><span style="font-size: 10pt">1-2)</span><span style="font-size: 10pt">用于安排工具条和其它窗口在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">环境中如何显示的选项。所谓的&ldquo;其它窗口&rdquo;包括许多特殊的窗口，比如观察点</span><span style="font-size: 10pt">(Watchpoints)</span><span style="font-size: 10pt">窗口，表达式</span><span style="font-size: 10pt">(Expressions)</span><span style="font-size: 10pt">窗口，过程</span><span style="font-size: 10pt">(Processes)</span><span style="font-size: 10pt">窗口和全局变量</span><span style="font-size: 10pt">(Global Variables)</span><span style="font-size: 10pt">窗口等。</span></div>
<div align="center"><span style="font-size: 7.5pt">图 </span><span style="font-size: 7.5pt">1-2: </span><span style="font-size: 7.5pt">查看菜单中的工具条子菜单</span></div>
<div><strong><span style="font-size: 10pt">查找菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">查找菜单用于在单个文件或硬盘的目录中查找指定的代码。你可以使用它来方便地替换文本块或在你的代码中搜索指定的项目。即使是在小工程中使用这个工具也非常方便。</span></div>
<div><strong><span style="font-size: 10pt">工程菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">工程菜单中的工具用于管理</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">工程。一个工程包括组成你正在编写的程序的所有的文件，包括头文件、源代码和库文件。工程窗口显示了所有这些文件的名称。我们将在第二课中深入讨论这部分内容。</span></div>
<div><strong><span style="font-size: 10pt">调试菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">这是在编制程序中最常用到的工具。我们将在第五课中详细介绍它的使用方法。</span></div>
<div><strong><span style="font-size: 10pt">窗口菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">用于在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">环境管理窗口显示方式的菜单。</span></div>
<div><strong><span style="font-size: 10pt">帮助菜单</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通过帮助菜单可以到网上寻求关于</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">任何问题的在线解答。够酷的吧？</span></div>
<div><span style="font-size: 10pt">　</span></div>
<div><font size="3"><strong><span style="color: black">了解</span></strong><strong><span style="color: black"> CodeWarrior </span></strong><strong><span style="color: black">集成开发环境的设置</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior IDE </span><span style="font-size: 10pt">提供了许多设置以便让你定制你的工作环境。当你选择了编辑菜单中的</span><span style="font-size: 10pt"> Preferences </span><span style="font-size: 10pt">项时，你将会看到一个设置对话框</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如图</span><span style="font-size: 10pt">1-3)</span><span style="font-size: 10pt">。在该对话框中，有控制</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">编辑器、调试器和其它许多功能的界面和行为的选项。在这一节中，我们将学习这些设置的使用。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">1-3:&nbsp; </span></em><em><span style="font-size: 7.5pt">设置对话框</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">你可以在自己的</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">中试试上述这些设置项。你可以先点击问号标志，然后点击你感兴趣的项目，就可以得到一个有关该项目的用途的简短介绍，也可以从帮助菜单中得到更详细的信息。</span></div>
<div><strong><span style="font-size: 10pt">通用设置</span></strong></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">编译设置</span></strong><strong><span style="font-size: 10pt">(Build Settings):</span></strong><span style="font-size: 10pt">选择是否在执行编译之前保存已打开的源文件，以及有多少内存被用于编译工作；</span></li>
    <li><strong><span style="font-size: 10pt">IDE </span></strong><strong><span style="font-size: 10pt">之外</span></strong><strong><span style="font-size: 10pt">(IDE Extras):</span></strong><span style="font-size: 10pt">几个独立的设置。比如指定</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">是否使用一个第三方的文本编辑器&mdash;&mdash;因为集成的编辑器并不是很完美，这可以通过指定一个你惯用的编辑器来替代它；</span></li>
    <li><strong><span style="font-size: 10pt">插件设置</span></strong><strong><span style="font-size: 10pt">(Plug-In Settings): </span></strong><span style="font-size: 10pt">供插件开发商调试他们的插件；</span></li>
    <li><strong><span style="font-size: 10pt">隐藏文件夹</span></strong><strong><span style="font-size: 10pt">(Shielded Folders):</span></strong><span style="font-size: 10pt">在这里指定的文件夹在工程设计期间，或执行查找和比较操作期间，将要被忽略掉。如果在你的工程级有一个巨大的&ldquo;数据&rdquo;文件目录，而你又不想让这些文件降低</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">的操作速度时，这个设置就很管用了；</span></li>
    <li><strong><span style="font-size: 10pt">资料树</span></strong><strong><span style="font-size: 10pt">(Source Trees):</span></strong><span style="font-size: 10pt">用于指定</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">在编译程序时用不着的目录。</span></li>
</ul>
<div><strong><span style="font-size: 10pt">编辑器设置</span></strong></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">编辑器设置</span></strong><strong><span style="font-size: 10pt">(Editor Settings):</span></strong><span style="font-size: 10pt">几个用于定制编辑器显示、管理文本和窗口的设置项；</span></li>
    <li><strong><span style="font-size: 10pt">字体和制表符</span></strong><strong><span style="font-size: 10pt">(Fonts and Tabs):</span></strong><span style="font-size: 10pt">设置编辑器中的文本大小、字体、制表符和其它显示设置；</span></li>
    <li><strong><span style="font-size: 10pt">文本颜色</span></strong><strong><span style="font-size: 10pt">(Text Colors):</span></strong><span style="font-size: 10pt">用于指定特定语言元素</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">比如程序的注释</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">在编辑窗口中的显示的颜色。</span></li>
</ul>
<div><strong><span style="font-size: 10pt">调试器设置</span></strong></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">显示设置</span></strong><strong><span style="font-size: 10pt">(Display Settings):</span></strong><span style="font-size: 10pt">几个用于定制调试器显示的设置项；</span></li>
    <li><strong><span style="font-size: 10pt">视窗化</span></strong><strong><span style="font-size: 10pt">(Windowing):</span></strong><span style="font-size: 10pt">设定调试器如何管理它的窗口</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">比如隐藏所有打开的编辑器窗口</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">；</span></li>
    <li><strong><span style="font-size: 10pt">全局设置</span></strong><strong><span style="font-size: 10pt">(Global Settings):</span></strong><span style="font-size: 10pt">几个用于定制调试器在全局层次如何工作的设置。比如当一个包含了程序调试信息的文件被打开时，是否启动这个程序；</span></li>
    <li><strong><span style="font-size: 10pt">远程连接</span></strong><strong><span style="font-size: 10pt">(Remote Connections):</span></strong><span style="font-size: 10pt">允许通过</span><span style="font-size: 10pt"> TCP/IP </span><span style="font-size: 10pt">进行远程调试。这样，你就可以在地球的另一边调试你的软件了；</span></li>
    <li><strong><span style="font-size: 10pt">Java </span></strong><strong><span style="font-size: 10pt">设置</span></strong><strong><span style="font-size: 10pt">/Java </span></strong><strong><span style="font-size: 10pt">调试</span></strong><strong><span style="font-size: 10pt">(Java Settings/Java Debugging):</span></strong><span style="font-size: 10pt">允许你设置特定的</span><span style="font-size: 10pt"> Java </span><span style="font-size: 10pt">编程语言选项。本课程不涉及这部分内容。</span></li>
</ul>
<div><strong><font size="3">RAD </font></strong><strong><span style="font-size: 10pt">工具</span></strong></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">Layout </span></strong><strong><span style="font-size: 10pt">编辑器</span></strong><strong><span style="font-size: 10pt">:</span></strong><span style="font-size: 10pt">几个用于在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">中定制快速应用程序开发工具的使用的设置。</span></li>
</ul>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">正如你所见到的，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">有许多设置项和选项。设置完后点击&ldquo;</span><span style="font-size: 10pt">Save</span><span style="font-size: 10pt">&rdquo;按钮保存你所作的修改，点击&ldquo;</span><span style="font-size: 10pt">Close</span><span style="font-size: 10pt">&rdquo;按钮将忽略你所作的所有修改。在进入下一节课之前，多练习几次。最后请确认&ldquo;默认的文本文件格式</span><span style="font-size: 10pt">(Default Text File Format)&rdquo;(</span><span style="font-size: 10pt">在编辑器设置面板中</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">保持为</span><span style="font-size: 10pt"> DOS </span><span style="font-size: 10pt">设置。</span></div>
<div align="center"><font size="3"><strong>第二课</strong>&nbsp;<strong>显示和定制工程和目标文件(1)</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">本课将讲述</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">操作文件的方式以及介绍它的工程</span><span style="font-size: 10pt">(Project)</span><span style="font-size: 10pt">窗口。</span></div>
<div><font size="3"><strong>什么是工程文件</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">为了使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">来创建一个应用程序，你必须创建许多文件来构成一个工程</span><span style="font-size: 10pt">(Project)</span><span style="font-size: 10pt">。该工程的设置和所有这些文件的指针都被存放在一个工程文件中。这些设置包括编译和链接设置、源文件、库文件以及它们之间用于产生最终程序的相互关系。你可以将这个工程文件看作该工程的大脑：它保存了所有文件相互依存的关系并知道如何将它们组合成为一个可用的应用程序。工程窗口依次显示了这些关于你的程序和该程序所包含的文件的信息，并允许你只需轻松点击就可以修改这个工程。图</span><span style="font-size: 10pt">2-1</span><span style="font-size: 10pt">显示了工程窗口的外观。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">2-1: </span></em><em><span style="font-size: 7.5pt">显示工程信息的工程窗口</span></em><em><span style="font-size: 7.5pt">(</span></em><em><span style="font-size: 7.5pt">图示为空的情况</span></em><em><span style="font-size: 7.5pt">)</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">大多数组成你的程序的文件都是原始的文本文件。这些文件包含了你在 </span><span style="font-size: 10pt">CodeWarrior</span><span style="font-size: 10pt">的编辑器中键入的源代码。在某些情况下，你还将使用一些预编译的源码和头文件。在进行数学运算和 </span><span style="font-size: 10pt">I/O </span><span style="font-size: 10pt">操作时，你还要使用到一些库文件，比如 </span><span style="font-size: 10pt">Metrowerks </span><span style="font-size: 10pt">标准库</span><span style="font-size: 10pt">(Metrowerks Standard Library</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">MSL) </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通常，你都是使用 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">来编写源代码，但通过给 </span><span style="font-size: 10pt">CodewWarrior </span><span style="font-size: 10pt">的集成开发环境加装相应的插件</span><span style="font-size: 10pt">(plug-in)</span><span style="font-size: 10pt">，你也可以在 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">中使用其它语言来进行编程。别忘了，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">可是一个可扩展的集成开发环境。通过给它安装一些插件，你就可以扩展它的功能。比如说，加入有人开发了一种新的叫做 </span><span style="font-size: 10pt">Z++ </span><span style="font-size: 10pt">的编程语言，你就可以为 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">创建一个相应的插件使之能够支持 </span><span style="font-size: 10pt">Z++ </span><span style="font-size: 10pt">语言，而且你还可以拿这个插件卖好多钱，让所有使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编程的人都使上 </span><span style="font-size: 10pt">Z++ </span><span style="font-size: 10pt">语言。那该多好！</span><span style="font-size: 10pt">:</span><span style="font-size: 10pt">）</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">现在你知道了 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">是如何使用文件的了。下面我们来详细地学习有关工程窗口的知识。</span></div>
<div><font size="3"><strong>工程窗口</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">当你启动 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">并打开或创建一个工程时，工程窗口就会显示出来。该窗口用于管理整个工程的所有文件以及这个工程将要产生的目标</span><span style="font-size: 10pt">(targets)</span><span style="font-size: 10pt">文件。一个工程包含了足够的信息来编译一个或多个目标文件。所谓的目标</span><span style="font-size: 10pt">(target)</span><span style="font-size: 10pt">文件就是当你编译程序时，由 </span><span style="font-size: 10pt">CodeWariior </span><span style="font-size: 10pt">创建出来的</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">通常是</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">一个应用程序或库文件。一些程序可以编译产生多个目标文件。比如，你可以编写一个程序来创建一个 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">和一个调用该 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">的主应用程序。在 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的工程中，你可以定义一个目标来产生 </span><span style="font-size: 10pt">DLL</span><span style="font-size: 10pt">，定义另一个目标来产生应用程序。通过这种方式，你的工程只需编译一次就可产生所有需要的目标文件或片断。图 </span><span style="font-size: 10pt">2-2 </span><span style="font-size: 10pt">显示了&ldquo;</span><span style="font-size: 10pt">Hello World</span><span style="font-size: 10pt">&rdquo;</span><span style="font-size: 10pt">程序的工程窗口。</span></div>
<div><em><span style="font-size: 10pt">图</span></em><em><span style="font-size: 10pt">2-2: </span></em><em><span style="font-size: 7.5pt">Hello World </span></em><em><span style="font-size: 7.5pt">程序的工程窗口</span></em><em><span style="font-size: 7.5pt">(</span></em><em><span style="font-size: 7.5pt">其中显示了所有包含于该程序中或用于编译该程序的文件</span></em><em><span style="font-size: 7.5pt">)</span></em></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">你可以看到，在这个工程窗口中确实包含了一些项目。在窗口的顶端有三个标签(tab)页：文件标签</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如图</span><span style="font-size: 10pt">2-2</span><span style="font-size: 10pt">显示</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">、链接顺序标签页和目标文件标签页</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">后两个标签页将在后续课程中讲述</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。在这几个标签页的上方，有一个用于选择要编译的目标文件的下拉菜单。在本例中，我们选择的是 </span><span style="font-size: 10pt">Hello World </span><span style="font-size: 10pt">工程的调试版本。在下拉菜单的右边有几个图标，它们的存在允许你不必使用菜单命令就可以方便地编译、链接和运行这个工程。</span></div>
<div style="margin: 0cm 36pt 0pt"><strong><span style="font-size: 10pt">注意</span></strong><strong><span style="font-size: 10pt">:</span></strong><span style="font-size: 10pt">在某些版本的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">中，链接标签被称为段</span><span style="font-size: 10pt">(segments)</span><span style="font-size: 10pt">标签。有些人可能在某些 </span><span style="font-size: 10pt">X86 </span><span style="font-size: 10pt">的处理器上编程时使用的是分段</span><span style="font-size: 10pt">(segmented)</span><span style="font-size: 10pt">代码。但使用 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">版的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">工具时就不是这样，这是产生的 </span><span style="font-size: 10pt">X86 </span><span style="font-size: 10pt">代码使用的是</span><span style="font-size: 10pt">&quot;</span><span style="font-size: 10pt">扁平的</span><span style="font-size: 10pt">&quot;(flat)</span><span style="font-size: 10pt">，或者叫做非分段的</span><span style="font-size: 10pt">(unsegmented) </span><span style="font-size: 10pt">内存空间。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">顾名思义，文件标签页列出了在工程中所有可能用到的文件。你可以通过创建一些组</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">用文件夹图标表示</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">来分门别类地管理这些文件，并可以帮助你方便地了解哪些文件将被使用。在本例中，我们将 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">程序</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">以</span><span style="font-size: 10pt">.c</span><span style="font-size: 10pt">为后缀名的文件</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">全都放到一个叫做 </span><span style="font-size: 10pt">Source </span><span style="font-size: 10pt">的组中，同时将库文件放到另一个组中，以便整洁明了地管理这些文件。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在 </span><span style="font-size: 10pt">Sources </span><span style="font-size: 10pt">组中有一个 </span><span style="font-size: 10pt">main.c </span><span style="font-size: 10pt">文件。因为我们还没有编译这个工程，所以在每个文件对应的 </span><span style="font-size: 10pt">Code </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Data </span><span style="font-size: 10pt">栏中显示数字的都是零。一旦我们编译了这个工程，这些数字就将显示出来，表示源码转换为机器代码后实际的代码量和数据量。可是，库文件 </span><span style="font-size: 10pt">ANSICX86.LIB </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">MWCRTL.LIB </span><span style="font-size: 10pt">后面显示的是 </span><span style="font-size: 10pt">n/a </span><span style="font-size: 10pt">。这表示索虽然这些文件被显示在这里，但是它们并不是 </span><span style="font-size: 10pt">Hello World </span><span style="font-size: 10pt">目标文件的一部分。这两个文件是用于不可调试</span><span style="font-size: 10pt">(non-debugging)</span><span style="font-size: 10pt">开发的，而本例不是这种情况。如果我们从菜单中修改本例的目标文件为 </span><span style="font-size: 10pt">Release(</span><span style="font-size: 10pt">发布</span><span style="font-size: 10pt">) </span><span style="font-size: 10pt">版本时，这两个文件就用得上了。这时这些文件后面的 </span><span style="font-size: 10pt">Code </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Data </span><span style="font-size: 10pt">栏目就会显示相应的数值。</span></div>
<div style="margin: 0cm 36pt 0pt"><strong><span style="font-size: 10pt">注意</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">在 </span><span style="font-size: 10pt">Data </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Code </span><span style="font-size: 10pt">栏右端的 </span><span style="font-size: 10pt">Target </span><span style="font-size: 10pt">栏目中的小子弹头也是用来表示该文件是否被当前编译生成的目标文件使用到。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">再往右边去，是 </span><span style="font-size: 10pt">Debug </span><span style="font-size: 10pt">栏</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">用一个绿色的小虫子表示</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，它是用于告诉你对应的文件在编译时是否要产生调试信息。我们将在第五课中详细论述这部分内容。最后，我们来看看在每一行最右端的弹出菜单，它是用于打开文件、更新源码、打开包含的头文件等等操作的快捷方式，具体是什么才作，要看它所代表的项目的类型而定。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">现在让我们来编译这个 </span><span style="font-size: 10pt">Hello World </span><span style="font-size: 10pt">工程并看看编译后的工程窗口的情况。我们从 </span><span style="font-size: 10pt">Project </span><span style="font-size: 10pt">菜单中选择 </span><span style="font-size: 10pt">Make </span><span style="font-size: 10pt">命令来编译该工程。这将更新所有需要编译的文件并产生相应的输出文件&mdash;&mdash;在本例中是 </span><span style="font-size: 10pt">Hello World </span><span style="font-size: 10pt">这个应用程序。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">2-3: </span></em><em><span style="font-size: 7.5pt">编译工程后的工程窗口的显示情况</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">从图</span><span style="font-size: 10pt">2-3</span><span style="font-size: 10pt">中我们可以看到，工程窗口发生了一些变化。</span><span style="font-size: 10pt">Code </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Data </span><span style="font-size: 10pt">栏都显示了当前工程中对应项的相应的数字。如果你打算看看编译前后存放这些文件的目录的话，你会发现编译后在该目录下产生了一些新的文件，如图</span><span style="font-size: 10pt">2-4</span><span style="font-size: 10pt">所示。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">2-4: </span></em><em><span style="font-size: 7.5pt">编译后将在工程目录中产生一些新的文件</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在本例中，编译工程后在工程目录中产生了一个新的文件。这就是 </span><span style="font-size: 10pt">X86 </span><span style="font-size: 10pt">目标文件输出&mdash;&mdash;生成一个叫做 </span><span style="font-size: 10pt">Hello World x86 </span><span style="font-size: 10pt">的应用程序。其它一些一直存在于这个目录中的文件是： </span><span style="font-size: 10pt">.mcp </span><span style="font-size: 10pt">文件&mdash;工程文件本省，以及 </span><span style="font-size: 10pt">.c </span><span style="font-size: 10pt">源文件&mdash;包含了应用程序源码的文件。</span><span style="font-size: 10pt">Hello World Data </span><span style="font-size: 10pt">目录中还包含了由 </span><span style="font-size: 10pt">CodwWarrior </span><span style="font-size: 10pt">生成的各种各样的支持文件。现在你还不必去关心这些文件。如果你正在编译目标文件的调试版本，你会看到更多的文件被产生出来，这些文件中可能包含着符号</span><span style="font-size: 10pt">(symbolic)</span><span style="font-size: 10pt">调试信息。集成开发环境的调试器使用这些符号信息来记录在高层次源码中的操作轨迹。我们将在第五课中详细讲述这方面内容。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">现在你已经了解了这些文件是如何结合在一起被编译生成一个目标文件的。让我们来运行这个目标文件并看看它的运行结果是什么样。你双击 </span><span style="font-size: 10pt">Hello World x86 </span><span style="font-size: 10pt">应用程序，就会有如图 </span><span style="font-size: 10pt">2-5</span><span style="font-size: 10pt">所示的结果显示出来。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">2-5: Hello World </span></em><em><span style="font-size: 7.5pt">应用程序的运行结果</span></em></div>
<div><font size="3"><strong>Putting It into Play</strong></font></div>
<div><span style="font-size: 10pt">Someday, you too may create something as lyrical and profound as Hello World. Possibly, with hard work and determination, you can do this by the end of the day. The source code to make this work is as follows:</span></div>
<pre style="margin: 0cm 36pt 0pt"><span><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></pre>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">#include </span></div>
<pre style="margin: 0cm 36pt 0pt"><span><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></pre>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">void main(void) { int c; printf(&quot;Hello World on Windows!\n&quot;); c = getchar(); </span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div><span style="font-size: 10pt">That's it! Who knew it could be so easy? Go on, you know you want to try it, but with some sort of profound statement instead of &quot;Hello World on Windows!&quot; Soon you'll be writing your own applications that not only can display text but can also perform other tasks for you. Before you know it, you'll be customizing AIBO dogs! That's Lesson 4. Well, okay, not really. Lesson 4 is Linking.</span></div>
<div><font size="3"><strong>What's That Other Function Doing There?</strong></font></div>
<div><span style="font-size: 10pt">Those already seasoned in the C language might be wondering what the character input&nbsp; function, <span style="color: red">getchar(),</span> is doing here. Typically, when an application completes its job, it terminates, and the OS cleans up after the program. This means the Hello World window disappears moments after the application finishes drawing the phrase &quot;Hello World on Windows!&quot; So that we can admire our handiwork, we put the brakes on the program by having it wait for a final keystroke before it terminates.</span></div>
<div><span style="font-size: 10pt">This is not a bug, but normal behavior. Honest. CodeWarrior does provide an alternate library that provides the C console I/O functions used here. This alternate library will not only halt the application after it finishes writing to a window but will also let you save the text output to a file.</span></div>
<div><font size="3"><strong><span style="color: black">Link Order</span></strong></font></div>
<div><span style="font-size: 10pt">When you build a program using multiple source files, the link order is very important. After compiling your source code, you must link the items in the proper order. You will use the Link Order tab to determine this order. In the case of the Hello World x86 target we've been working with (Figure 2-6), note that the main.c source file is first on the list, with the libraries used by the program following. To reach the Link Order tab, open the project and click the tab. To change the order by which files are linked, you simply drag items up and down the list within this window. We will discuss Linking in more detail in Lesson 4.</span></div>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-6: Back in the Project window, clicking the Link Order tab displays a list of component files included in the current project.</span></em></div>
<div><font size="3"><strong>Targets</strong></font></div>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-7: The Hello World project's Target tab.</span></em></div>
<div><span style="font-size: 10pt">After you've chosen the files and defined their link order, you must configure the target. The target is essentially the output file -- in our case, the Hello World application. There are also a lot of settings that must be set behind the scenes to make it possible for you to hit the target. If you double-click the Hello World target in the Targets Tab (Figure 2-7), you should see the dialog box shown in Figure 2-8.</span></div>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-8: Set targeting preferences in the Settings window.</span></em></div>
<div><font size="3"><strong><span style="color: black">Configuring Target Settings</span></strong></font></div>
<div><span style="font-size: 10pt">The preferences you learned about in Lesson 1 are global settings used throughout the CodeWarrior IDE. Now, let's take a look at options for configuring target options. I will briefly examine the most important of these options. Follow along in your copy of CodeWarrior by double-clicking an item under the Target tab to bring up the Settings panel.</span></div>
<div><span style="font-size: 10pt">If you want a little extra guidance, move your cursor over an item in the panel, right-click it, and read the pop-up help text that appears.</span></div>
<div style="margin: 0cm 36pt 0pt"><strong><span style="font-size: 10pt">Note:</span></strong><span style="font-size: 10pt"> Some of the items listed below are specific to the target we are currently viewing, in this case the Hello World target. If you're using AMD's K6 or Athlon processors, some of these panels may contain items that use features specific to that chip. Consult the documentation for the compiler/linker that you are using to ensure that you are making the best use of your development environment. </span></div>
<div><font size="3"><strong>Target Preferences</strong></font></div>
<div><span style="font-size: 10pt">Target preferences include the following items, each with its own panel: </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">Target Settings:</span></strong><span style="font-size: 10pt"> Choose the target's name (the name that appears in the target pop-up menu), which linker(s) to use, and the output directory here. </span></li>
    <li><strong><span style="font-size: 10pt">Access Paths:</span></strong><span style="font-size: 10pt"> Access paths tell CodeWarrior where to search for required files that are a part of the project but not necessarily project-specific (such as header files). CodeWarrior will not, by default, search your entire hard disk for files. It will only look where you explicitly tell it to look with access paths. </span></li>
    <li><strong><span style="font-size: 10pt">Build Extras:</span></strong><span style="font-size: 10pt"> A few miscellaneous settings to improve the build speed. </span></li>
    <li><strong><span style="font-size: 10pt">Runtime Settings:</span></strong><span style="font-size: 10pt"> In order to debug non-application code, such as a plug-in, you must have an application assist you. The application does this by calling the suspect plug-in code. This panel lets you specify the host application to use in this situation. This topic will be mentioned in Lesson 8. </span></li>
    <li><strong><span style="font-size: 10pt">File Mappings:</span></strong><span style="font-size: 10pt"> Every file must be mapped so as to identify it to the compiler. That is, this panel tells CodeWarrior that files ending in .cpp are C++ source files and should therefore be compiled using the C++ compiler. See Figure 2-9 for more examples. </span></li>
</ul>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-9: The File Mappings options allow you to specify the treatment of files, based on their extension.</span></em></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">Source Trees:</span></strong><span style="font-size: 10pt"> Source trees are similar to access paths. Here you can enter file locations, such as file servers, that are specific to your project. </span></li>
    <li><strong><span style="font-size: 10pt">x86 Target:</span></strong><span style="font-size: 10pt"> This panel allows you to set the type of project (application, library, or DLL), and various aspects of the project -- including how much memory the resulting program requires. It is also where you specify the name of the file output by the IDE. This name can -- and usually will -- be different from the target's name (the one entered into the Target Settings panel). </span></li>
</ul>
<div><span style="font-size: 10pt">　</span></div>
<div><strong><span style="color: black">Setting Other Preferences</span></strong></div>
<div><span style="font-size: 10pt">CodeWarrior includes a variety of additional preferences that can help you customize your environment before beginning to work on your own programs.</span></div>
<div><font size="3"><strong>Language Settings</strong></font></div>
<div><span style="font-size: 10pt">Language Settings include the following items: (discussed further in Lesson 3) </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">C/C++ Language:</span></strong><span style="font-size: 10pt"> There are an extremely large number of settings for the C/C++ compiler. Suffice it to say that you can alter them here. See Figure 2-11. </span></li>
</ul>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-10: C++ Language settings.</span></em></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">C/C+ Warnings:</span></strong><span style="font-size: 10pt"> These settings (Figure 2-10) tell the C/C++ compiler whether to provide warnings as your code is being compiled. Sometimes source code can contain elements that aren't quite correct but are not necessarily errors. These are called warnings. You can instruct the compiler to treat all warnings as errors so that you can quickly examine the questionable code in the editor. </span></li>
    <li><strong><span style="font-size: 10pt">Windows RC:</span></strong><span style="font-size: 10pt"> A Windows-specific resource compiler. Resources are graphic elements (such as windows, buttons, and menu items) that can be built independent of your program code. This panel lets you specify a header file that the resource compiler uses when generating these interface elements. </span></li>
</ul>
<div><font size="3"><strong>Code Generation</strong></font></div>
<div><span style="font-size: 10pt">Code Generation preferences include the following items: </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">x86 Processor:</span></strong><span style="font-size: 10pt"> There are a number of decisions your compiler must make as it generates the machine code from your C or C++ source code. The settings in this panel help the compiler to optimize your code. This item will be labeled differently on each CodeWarrior platform. Figure 2-11 shows the x86 version. This is discussed more in Lesson 3. </span></li>
</ul>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-11: x86 Processor settings are specific to projects intended for a x86-based computer. CodeWarrior includes settings for each operating system it supports (directly, or through plug-ins).</span></em></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">Global Optimizations:</span></strong><span style="font-size: 10pt"> This has got to be one of the most exciting and useful panels in all of CodeWarrior (see Figure 2-12). This panel allows you to set the global optimization level of the compiler. This means that you can control how efficient and fast the compiler tries to make your source code. However, speed comes at a price. The smaller and faster the source code, the more difficult it is to debug, and the longer it takes to compile. Fortunately, the panel spells it all out for you so you can make that decision <em>every time you optimize!</em> If you want to, I mean. You will have a great deal of fun with this panel as you adjust the settings to suit your needs and your projects. </span></li>
</ul>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-12: Use Global Optimization settings to speed up compiling of the code (Optimizations Off), or make your code execute faster (Levels 1 through 4).</span></em></div>
<div><font size="3"><strong>Linker Preferences</strong></font></div>
<div><span style="font-size: 10pt">Linker preferences include the following items: </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">x86 Disassembler:</span></strong><span style="font-size: 10pt"> The name and specific settings in this panel may differ a bit by platform, but the options are similar. They allow you to configure specific settings that the Linker must use when disassembling and debugging your target. </span></li>
    <li><strong><span style="font-size: 10pt">x86 Linker:</span></strong><span style="font-size: 10pt"> The name and specific settings in this panel may differ a bit by platform, but the settings are similar (Figure 2-14). They allow you to configure specific settings that the Linker must use when building your target, such as specifying the entry point into your code. See Lesson 4. </span></li>
</ul>
<div align="center"><em><span style="font-size: 7.5pt">Figure 2-13: Each supported operating has a Linker settings panel. Here is the x86 version.</span></em></div>
<div><span style="font-size: 10pt">Settings for the editor can be found on the Custom Keywords panel. This panel allows you to configure the text editor to display various custom keywords in different colors. For example, if you like to use a keyword in your source code to label certain areas of the code in a different color, you can list it here. It will appear in the color you choose.</span></div>
<div><span style="font-size: 10pt">The Debugger Settings panel allows you to choose how the debugger should log data, handle watch points, etc. This is discussed in more detail in Lesson 5.</span></div>
<div><span style="font-size: 10pt">Now you can begin to see how CodeWarrior's features help make programming easier. Now go check out your homework. Yes, you will have some homework assignments in this class. Then I'll see you back here for Lesson 3.</span></div>
<div align="center"><font size="3"><strong>第三课</strong>&nbsp;<strong>&nbsp;&nbsp; </strong><strong>编<span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 译</span></strong></font></div>
<div><strong><span style="color: black">第一步：理解编译阶段</span></strong></div>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">我们的前面的课程中已经学到，源程序输入完之后的工作就是要编译它。编译源程序就是计算机把你所写</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">通常是用</span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++</span><span style="font-size: 10pt">编写的</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">的源代码进行分解、分析，然后转化为机器语言。机器语言是一种计算机能够理解阿语言，而且它运行起来比 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">也要快得多。编译的大致过程如下：</span></div>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">&nbsp;1. </span><span style="font-size: 10pt">用 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">编写代码：</span></div>
<div style="margin: 0cm 72pt 0pt"><span style="font-size: 10pt">#include <br />
void main(void) { <br />
&nbsp;&nbsp; int c; <br />
&nbsp;&nbsp; printf(&quot;Hello World on Windows!\n&quot;); <br />
&nbsp;&nbsp; c = getchar(); <br />
}</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">2. </span><span style="font-size: 10pt">进行编译。 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编译上述代码并把它翻译成机器语言，结果如下： </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">符号名：</span></div>
<div><span style="font-size: 6.5pt">&nbsp;1: _main 2: _@8 3: _printf 4: ___files 5: _fwide 6: ___get_char =============================================================== <br />
SECTION SIZE = 0x0000003C; NAME =?.text DEFINED SYMBOLS: name = _main offset = 0x00000000; type = 0x0020; class = 0x0002 00000000: 68 00 00 00 00 push offset _@8 00000005: E8 00 00 00 00 call _printf 0000000A: 59 pop ecx 0000000B: 6A FF push -1 0000000D: 68 00 00 00 00 push offset ___files 00000012: E8 00 00 00 00 call _fwide 00000017: 85 C0 test eax,eax 00000019: 59 pop ecx 0000001A: 59 pop ecx 0000001B: 7D 1E jge $+32 ; --&gt; 0x003b 0000001D: 83 2D 2C 00 00 00 sub dword ptr ___files+44,1 00000023: 01 00000024: 72 0A jb $+12 ; --&gt; 0x0030 00000026: FF 05 28 00 00 00 inc dword ptr ___files+40 0000002C: EB 0D jmp $+15 ; --&gt; 0x003b 0000002E: 89 C0 mov eax,eax 00000030: 68 00 00 00 00 push offset ___files 00000035: E8 00 00 00 00 call ___get_char 0000003A: 59 pop ecx 0000003B: C3 ret near <br />
============================================================= SECTION SIZE = 0x00000019; NAME = .data 00000000: 48 65 6C 6C 6F 20 57 6F 72 6C 64 20 6F 6E 20 57 Hello World on W 00000010: 69 6E 64 6F 77 73 21 0A 00 indows! DEFINED SYMBOLS: name = _@8 offset = 0x00000000; type = 0x0000; class = 0x0003 ============================================================== </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">上述机器代码难于阅读，不要去管它。机器代码相比 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">而言，要难理解多了。但是，计算机只能理解机器语言。只有将你的程序编译&mdash;或翻译&mdash;成机器代码，然后再执行它，这样运行起来才能快一些，而不是每次运行时才去翻译它，那样运行速度就很慢了。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">你只需选定一个源文件，然后从工程菜单中选择反汇编项，你就能看到该文件的机器语言清单。实际上上面我们看到的机器语言清单就是这样得到的。如果你仔细地对照阅读一下你的 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">源代码和它编译后的机器代码，不难发现它们之间的关系。</span></div>
<div><font size="3"><strong><span style="color: black">CodeWarrior </span></strong><strong><span style="color: black">中编译选项的详细设置</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在正式开始编译源代码之前，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">还要对其做预处理。在这个阶段，是对 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">代码进行编译前的一些准备工作。在编写程序的过程中，往往会有很多相同的</span><span style="font-size: 10pt">P</span><span style="font-size: 10pt">代码输入，于是程序员使用一些快捷方式，比如所谓的宏</span><span style="font-size: 10pt">(macros)</span><span style="font-size: 10pt">来代替这些相同的输入。例如，你可以使用 </span><span style="font-size: 10pt">APPNAME </span><span style="font-size: 10pt">作为一个宏，来表示&ldquo;</span><span style="font-size: 10pt">Metrowerks CodeWarrior</span><span style="font-size: 10pt">&rdquo;</span><span style="font-size: 10pt">，以此来减少输入的工作量。预处理就是要把这些宏转换为它们实际表示的代码，此外还要替换一些定义符号</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">比如 </span><span style="font-size: 10pt">#define THREE 3)</span><span style="font-size: 10pt">为实际的源代码。为了更好地理解预处理所做的工作，你可以查看一下预处理结果的清单。首先在工程窗口中选中一个源文件，然后从工程菜单中选择预处理项，你就可以看到源代码进行了预处理之后，编译之前的结果清单了。</span><span style="font-size: 10pt">.</span></div>
<div><font size="3"><strong>定制 </strong><strong>CodeWarrior </strong><strong>的编译方式</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在第二课中，我们已经了解了一些控制 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编译代码的选项对话框。现在我们再来详细地看看一些标准 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">编译器的设置。请你按照下面所学内容在你的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">上进行实际的操作练习。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">3-1: </span></em><em><span style="font-size: 7.5pt">控制 </span></em><em><span style="font-size: 7.5pt">CodeWarrior </span></em><em><span style="font-size: 7.5pt">进行</span></em><em><span style="font-size: 7.5pt">&nbsp; C/C++ </span></em><em><span style="font-size: 7.5pt">编译的语言设置</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">从编辑菜单中选择 </span><span style="font-size: 10pt">Hello World X86 setting </span><span style="font-size: 10pt">项来打开设置窗口。现在，点击图</span><span style="font-size: 10pt">3-1</span><span style="font-size: 10pt">中语言设置类</span><span style="font-size: 10pt">(Language Settings category)</span><span style="font-size: 10pt">下面的 </span><span style="font-size: 10pt">C/C++ </span><span style="font-size: 10pt">语言标签</span><span style="font-size: 10pt">(C/C++ Language label)</span><span style="font-size: 10pt">，你就可以看到</span><span style="font-size: 10pt">C/C++ </span><span style="font-size: 10pt">语言设置对话框中的许多选项。我们逐个来学习这些选项，以便了解它们是如何影响编译的过程的。 </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">激活</span></strong><strong><span style="font-size: 10pt">C++ </span></strong><strong><span style="font-size: 10pt">编译器</span></strong><strong><span style="font-size: 10pt">(Activate C++ Compiler):</span></strong><span style="font-size: 10pt">这个选项允许你把所有后缀名为</span><span style="font-size: 10pt">.c </span><span style="font-size: 10pt">的源文件当作</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">文件来进行编译。如果你想在</span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">源码中使用一些</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">语言的特色时，这个功能就很有用了；</span></li>
    <li><strong><span style="font-size: 10pt">ARM </span></strong><strong><span style="font-size: 10pt">一致性</span></strong><strong><span style="font-size: 10pt">(ARM Conformance):</span></strong><span style="font-size: 10pt">编译器要求你的代码遵循</span><span style="font-size: 10pt">ANSI C++ </span><span style="font-size: 10pt">的标准。但你可以通过选中这个选项来指定你的编译器遵循</span><span style="font-size: 10pt">&ldquo;</span><span style="font-size: 10pt">注释</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">参考手册</span><span style="font-size: 10pt">&rdquo;</span><span style="font-size: 10pt">(Annotated C++ Reference Manual</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">ARM) </span><span style="font-size: 10pt">中的标准；</span></li>
    <li><strong><span style="font-size: 10pt">允许</span></strong><strong><span style="font-size: 10pt">C++ </span></strong><strong><span style="font-size: 10pt">例外</span></strong><strong><span style="font-size: 10pt">(Enable C++ Exceptions):</span></strong><span style="font-size: 10pt">选中这个选项将允许你在</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">代码中使用</span><span style="font-size: 10pt">try/catch/throw </span><span style="font-size: 10pt">等块</span><span style="font-size: 10pt">(blocks)</span><span style="font-size: 10pt">。这些方法用于书写错误管理器</span><span style="font-size: 10pt">(writing error handlers)</span><span style="font-size: 10pt">；</span></li>
    <li><strong><span style="font-size: 10pt">允许</span></strong><strong><span style="font-size: 10pt">RTTI(Enable RTTI): </span></strong><span style="font-size: 10pt">RTTI </span><span style="font-size: 10pt">表示</span><span style="font-size: 10pt">Run Time Type Information(</span><span style="font-size: 10pt">运行类型信息</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。这个选项运息编译器判定一个</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">对象在运行中的类型。这是</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">的高级特色，在很多情况下都是很有用的。如果你想了解更多关于</span><span style="font-size: 10pt">RTTI </span><span style="font-size: 10pt">的信息，请查阅你的</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">手册；</span></li>
    <li><strong><span style="font-size: 10pt">内联深度</span></strong><strong><span style="font-size: 10pt">/</span></strong><strong><span style="font-size: 10pt">自动内联</span></strong><strong><span style="font-size: 10pt">/</span></strong><strong><span style="font-size: 10pt">延期内联</span></strong><strong><span style="font-size: 10pt">(Inline Depth/Auto-Inline/Deferred Inlining):</span></strong><span style="font-size: 10pt">这些是关于源代码中使用的内联函数的一些设置项。所谓内联函数，就是在编译时该函数的源代码将被直接插入到程序体中，而不是产生这个函数的调用。在某些情况下，使用内联函数可以提高代码的性能。这是编译器的一个高级设置项；</span></li>
    <li><strong><span style="font-size: 10pt">字符串池</span></strong><strong><span style="font-size: 10pt">(Pool Strings):</span></strong><span style="font-size: 10pt">通常，编译器将编译后代码中的所有字符串对象存储到它们自己的数据空间中。如果你想将所有的这些字符串存放到一个数据空间中，就应该选中此项。如果你的源代码中有非常多的字符串</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">比如上面我们提到的</span><span style="font-size: 10pt">APPNAME </span><span style="font-size: 10pt">宏</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，那么你就应该选中此项来节省内存空间。这个功能只能在使用</span><span style="font-size: 10pt">PowerPC </span><span style="font-size: 10pt">的</span><span style="font-size: 10pt">Mac OS </span><span style="font-size: 10pt">平台上编程时使用；</span></li>
    <li><strong><span style="font-size: 10pt">不重用字符串</span></strong><strong><span style="font-size: 10pt">(Don't Reuse Strings):</span></strong><span style="font-size: 10pt">所谓</span><span style="font-size: 10pt">&ldquo;</span><span style="font-size: 10pt">重用字符串</span><span style="font-size: 10pt">&rdquo;</span><span style="font-size: 10pt">，就是指当你的程序中有几个完全一样的字符串时，编译器会将它们全都存放到同一个数据空间里。但是，有时你可能想修改某个字符串，这就会造成其它和要修改字符串共享数据空间的字符串也要被修改了。如果你想避免这种情况，就要选中这个选项。这样，即使程序中有完全一样的字符串，它们也将存放到不同的数据空间中；</span></li>
    <li><strong><span style="font-size: 10pt">要求有函数原型</span></strong><strong><span style="font-size: 10pt">(Require Function Prototypes):</span></strong><span style="font-size: 10pt">建议最好选中此项。使用函数原型可以帮助编译器在检查传递给函数的参数类型时发现代码中的错误。所谓函数原型就是在程序的前端对函数进行声明。也就是说，你应当在使用一个函数之前，定义或声明这个函数。既然这个选项这么好，那么什么时候应该关掉它呢？通常是，当你使用一些老版本的</span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">进行编程时，并不需要对函数进行事先声明，这时你就应该关掉这个选项来检查整个程序代码。你一定愿意在程序前端书写函数原型，并选中此选项，因为它能帮助你解决这么多的编码错误；</span></li>
    <li><strong><span style="font-size: 10pt">允许支持布尔变量</span></strong><strong><span style="font-size: 10pt">(Enable bool Support):</span></strong><span style="font-size: 10pt">为了使用</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">的布尔变量</span><span style="font-size: 10pt">&mdash;&mdash; </span><span style="font-size: 10pt">true (</span><span style="font-size: 10pt">真</span><span style="font-size: 10pt">) </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt">false (</span><span style="font-size: 10pt">假</span><span style="font-size: 10pt">) </span><span style="font-size: 10pt">这两个关键字，必须选中此项；</span></li>
    <li><strong><span style="font-size: 10pt">允许支持</span></strong><strong><span style="font-size: 10pt">wchar_t(Enable wchar_t Support):</span></strong><span style="font-size: 10pt">为了使用</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">的内置类型</span><span style="font-size: 10pt">wchar_t </span><span style="font-size: 10pt">而不是</span><span style="font-size: 10pt">char </span><span style="font-size: 10pt">类型来表示字符类型，必须选中此项；</span></li>
    <li><strong><span style="font-size: 10pt">严格遵循</span></strong><strong><span style="font-size: 10pt">ANSI/</span></strong><strong><span style="font-size: 10pt">只能使用</span></strong><strong><span style="font-size: 10pt">ANSI </span></strong><strong><span style="font-size: 10pt">关键字</span></strong><strong><span style="font-size: 10pt">(ANSI Strict/ANSI Keywords Only):</span></strong><span style="font-size: 10pt">默认情况下，编译器允许你使用</span><span style="font-size: 10pt">Metrowerks </span><span style="font-size: 10pt">扩展和</span><span style="font-size: 10pt">C/C++ </span><span style="font-size: 10pt">语言的附加关键字。但是如果你想在这种情况时编译报错，那么就应该选中这两项。这样，编译出来的程序就是</span><span style="font-size: 10pt">100% ANSI </span><span style="font-size: 10pt">兼容代码；</span></li>
    <li><strong><span style="font-size: 10pt">扩展通配符</span></strong><strong><span style="font-size: 10pt">(Expand Trigraphs):</span></strong><span style="font-size: 10pt">默认情况下，通配符是不允许的。为了能够使用通配符，就要选中此项。所谓通配符，就是在你的源代码中代表字符常量的方式。例如，</span><span style="font-size: 10pt">'????' </span><span style="font-size: 10pt">就是一个通配符；</span></li>
    <li><strong><span style="font-size: 10pt">多字节敏感</span></strong><strong><span style="font-size: 10pt">(Multi-Byte Aware</span></strong><span style="font-size: 10pt">)<strong>:</strong> </span><span style="font-size: 10pt">如果你是有能够的编程语言要求使用多字节字符</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">例如</span><span style="font-size: 10pt">Kanji </span><span style="font-size: 10pt">或</span><span style="font-size: 10pt">Unicode)</span><span style="font-size: 10pt">，就要选中此项。这样编译器才能正确地处理源代码中的多字节字符；</span></li>
    <li><strong><span style="font-size: 10pt">指示到</span></strong><strong><span style="font-size: 10pt">SOM (Direct to SOM):</span></strong><span style="font-size: 10pt">这是</span><span style="font-size: 10pt">Macintosh </span><span style="font-size: 10pt">平台上才有的功能，它允许你在</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">中直接创建</span><span style="font-size: 10pt">SOM </span><span style="font-size: 10pt">代码。</span><span style="font-size: 10pt">SOM </span><span style="font-size: 10pt">是一种使用于苹果机上的开放文档环境的代码类型，但现在已没人用了；</span></li>
    <li><strong><span style="font-size: 10pt">使用</span></strong><strong><span style="font-size: 10pt">CR </span></strong><strong><span style="font-size: 10pt">为换行符</span></strong><strong><span style="font-size: 10pt">(Map Newlines to CR):</span></strong><span style="font-size: 10pt">这个选项允许你交换</span><span style="font-size: 10pt">'\n' </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt">'\r' (</span><span style="font-size: 10pt">这是用于标识源码行结束的符号</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。此选项只对</span><span style="font-size: 10pt">Mac OS </span><span style="font-size: 10pt">上的编程有用；</span></li>
    <li><strong><span style="font-size: 10pt">不严格的指针类型规则</span></strong><strong><span style="font-size: 10pt">(Relaxed Pointer Type Rules):</span></strong><span style="font-size: 10pt">选中此项将把</span><span style="font-size: 10pt">char *, unsigned char *, void * </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt">Ptr </span><span style="font-size: 10pt">当作是同一种类新。当你从另一个并没有正确管理指针类型的源代码中，或者是从一个使用还不能正确支持这些类型的老编译平台上开发的源代码中继承代码时，这个选项就很有用了；</span></li>
    <li><strong><span style="font-size: 10pt">枚举类型总是整型</span></strong><strong><span style="font-size: 10pt">(Enums Always Ints):</span></strong><span style="font-size: 10pt">通常情况下，编译器将一个枚举类型分配与之最接近的类型同样的空间。如果你想使枚举类型的空间总是和整型一样，那么就要选中此项。所谓枚举类型就像这样：</span><span style="font-size: 10pt">enum {itemone, itemtwo = 7, itemthree}</span><span style="font-size: 10pt">。其中，</span><span style="font-size: 10pt">itemone </span><span style="font-size: 10pt">等于</span><span style="font-size: 10pt">0</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">itemtwo </span><span style="font-size: 10pt">等于</span><span style="font-size: 10pt">7</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">itemthree </span><span style="font-size: 10pt">等于</span><span style="font-size: 10pt">8</span><span style="font-size: 10pt">；</span></li>
    <li><strong><span style="font-size: 10pt">使用无符号字符类型</span></strong><strong><span style="font-size: 10pt">(Use Unsigned Chars):</span></strong><span style="font-size: 10pt">选中此项将把所有字符数据类型当作无符号字符类型来处理；</span></li>
    <li><strong><span style="font-size: 10pt">EC++ </span></strong><strong><span style="font-size: 10pt">兼容模式</span></strong><strong><span style="font-size: 10pt">(EC++ Compatibility Mode):</span></strong><span style="font-size: 10pt">使用</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编译嵌入式</span><span style="font-size: 10pt">C++ (EC++) </span><span style="font-size: 10pt">代码时，要选中此项。请注意，此时</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">中的诸如模板</span><span style="font-size: 10pt">(templates)</span><span style="font-size: 10pt">、例外</span><span style="font-size: 10pt">(exceptions)</span><span style="font-size: 10pt">和其它一些</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">的高级功能就不可用了。具体情况请查阅</span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">手册；</span></li>
    <li><strong><span style="font-size: 10pt">允许</span></strong><strong><span style="font-size: 10pt">Objective C(Enable Objective C):</span></strong><span style="font-size: 10pt">为了使用</span><span style="font-size: 10pt">Objective C (</span><span style="font-size: 10pt">在</span><span style="font-size: 10pt">NeXT </span><span style="font-size: 10pt">计算机操作系统上很著名的编程语言</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，要选中此项。此选项只能在</span><span style="font-size: 10pt">Mac OS </span><span style="font-size: 10pt">下只用；</span></li>
    <li><strong><span style="font-size: 10pt">前缀文件</span></strong><strong><span style="font-size: 10pt">(Prefix File):</span></strong><span style="font-size: 10pt">如果需要在每个源文件中包括一个头或预编译头文件，就要将该文件名输入在此处。适用情况：当所有源文件都要访问一个特殊的定义，但你又不想在每个源文件中键入</span><span style="font-size: 10pt">#include </span><span style="font-size: 10pt">来包括该定义时，使用此选项很方便。</span></li>
</ul>
<div style="text-indent: 13.5pt"><strong><span style="font-size: 10pt">注意</span></strong><strong><span style="font-size: 10pt">:</span></strong><span style="font-size: 10pt">上述许多选项在 </span><span style="font-size: 10pt">Mac OS </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">平台上的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">编译器版本中都是一样的。但根据我们在上面对这些编译器选项的描述可知，一些选项在两个平台上还是有一些不同的。然而，</span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">时平台无关的编程语言，因此大多数概念都是可以应用于任何平台的。</span></div>
<div align="center"><font size="3"><strong>第四课</strong>&nbsp;&nbsp;&nbsp; <strong>连</strong>&nbsp; <strong>接</strong></font></div>
<div><strong><span style="color: black">第二步：连接程序各部件</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">当你的程序编译完毕以后，接着就要使用连接器来把这些组成你的程序的各个文件连接起来。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">连接器是用来组合各个源文件被编译后得到编译代码的，同时还要将这些文件与它们所需要的库连接在一起。连接确保了每片代码都知道如何去找到你程序中的其它元素。例如，连接器修改机器代码以便使用 </span><span style="font-size: 10pt">MSL </span><span style="font-size: 10pt">库函数中的 </span><span style="font-size: 10pt">printf() </span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">该函数用来实现功能强大的控制台输入/输出)来替换你在源文件中使用的 </span><span style="font-size: 10pt">printf() </span><span style="font-size: 10pt">函数调用。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">当你编写一个程序时，常常将代码写成函数并存放在不同的文件中，然后将这些文件编译得到单个的输出文件。就像我们在前面使用的 </span><span style="font-size: 10pt">Hello World </span><span style="font-size: 10pt">这个程序，它的输出文件是一个应用程序。但是在某些时候，同一个程序中使用的函数在输出时不一定是存放在同一个输出文件中的。例如，假设你编写一个应用程序时，其中包含了许多被程序的多个部分重复使用的代码，你就可以将这些被重复使用的代码编译成为一个可共享的动态链接库</span><span style="font-size: 10pt">(DLL)</span><span style="font-size: 10pt">。这样，该应用程序仍然可以访问到这些代码，但是它就需要弄明白应该到哪个文件以及如何找到这些它需要使用的函数。这种情况，就需要做一些连接的工作了。</span></div>
<div><font size="3"><strong>连接的类型</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在程序的编制中，一个连接就是一个指针，指向一个象编译函数这样的对象，或者指向一个变量或一个数组这样的数据内容。连接有两种方式：硬连接(hard linking)和软连接(soft linking)。 </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">硬连接发生于连接过程中，说明代码的时候。换句话说，如果一个函数被使用了，在连接时连接器确切地知道这个函数在哪里并创建一个连接把这个函数连接起来。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">软连接</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">也称为弱连接</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">发生于进行连接时，一些代码可以不需要进行说明，因为你知道这些代码位于一个 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">中，并在运行时可以从该 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">中进行调用。在这种情况下，连接器会告诉应用程序到哪里去找它所需要的代码。<span>&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">软连接也是计算机操作系统中许多元素使用的方法。接下来，我们一起来学习一些关于连接器的选项设置。</span></div>
<div><font size="3"><strong><span style="color: black">A </span><span style="color: black">连接</span></strong><strong><span style="color: black">Detailed Look at Linking</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">为了将来能更好地领略 </span><span style="font-size: 10pt">CodeWarrior for Windows </span><span style="font-size: 10pt">平台的卓越功能，你首先需要了解如何配置 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的连接器来满足你的要求。</span></div>
<div><font size="3"><strong>根据你的要求来配置连接器</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">本课中使用的示例是运行在 </span><span style="font-size: 10pt">x86 </span><span style="font-size: 10pt">平台上的</span><span style="font-size: 10pt">&nbsp; CodeWarrior </span><span style="font-size: 10pt">的连接器设置面板</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如图</span><span style="font-size: 10pt">4-1)</span><span style="font-size: 10pt">。但是在这其中使用的很多术语也是适用于其它平台上的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">连接器的。</span></div>
<div>图 4-1&nbsp; x86 连接器设置窗口</div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通过选择编辑菜单中的&ldquo;工程名&rdquo;项来打开这个设置窗口。</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">&ldquo;工程名&rdquo;是指当前的活动工程&mdash;&mdash;在本例中就是</span><span style="font-size: 10pt"> Hello World x86)</span><span style="font-size: 10pt">，然后点击设置窗口中的</span><span style="font-size: 10pt"> x86 </span><span style="font-size: 10pt">连接器</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">或类似的名字</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">标签。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">下面我们来看看一些连接器设置项：</span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">入口点用法</span></strong><strong><span style="font-size: 10pt">(Entry Point Usage):</span></strong><span style="font-size: 10pt">在</span><span style="font-size: 10pt"> Windows OS </span><span style="font-size: 10pt">体系中，每一个代码模块都有许多可能可以或者不可以选择的入口点，这取决于你所编译的代码类型。这些入口点的自然属性依赖于你正在编写的程序的输出文件</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">应用程序、库或</span><span style="font-size: 10pt"> DLL )</span><span style="font-size: 10pt">的类型和其它的一些因素。当一个应用程序需要调用一个</span><span style="font-size: 10pt"> DLL </span><span style="font-size: 10pt">函数时，主机操作系统就使用这个入口点信息来正确地调用该</span><span style="font-size: 10pt"> DLL </span><span style="font-size: 10pt">地初始化函数。大多数情况下，你应当设置此选项为默认方式</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如图</span><span style="font-size: 10pt">4-1</span><span style="font-size: 10pt">所示</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。这将让</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">根据你在目标文件设置面板中选择的目标文件类型，来自动地为输出文件设置正确的入口点；</span></li>
    <li><strong><span style="font-size: 10pt">子系统</span></strong><strong><span style="font-size: 10pt">(Subsystem): </span></strong><span style="font-size: 10pt">子系统有三种选择：</span><span style="font-size: 10pt">Native</span><span style="font-size: 10pt">、</span><span style="font-size: 10pt"> Windows CUI </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> Windows GUI</span><span style="font-size: 10pt">。</span><span style="font-size: 10pt">Native </span><span style="font-size: 10pt">选项是用于开发驱动程序和其它异种系统模块的；</span><span style="font-size: 10pt"> Windows CUI </span><span style="font-size: 10pt">选项是用于开发使用控制台风格用户界面</span><span style="font-size: 10pt">( console-style user interface</span><span style="font-size: 10pt">，所谓的</span><span style="font-size: 10pt">CUI )</span><span style="font-size: 10pt">的应用程序的；</span><span style="font-size: 10pt">Windows GUI </span><span style="font-size: 10pt">选项用于开发使用</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">图形用户界面</span><span style="font-size: 10pt">(Windows graphic user interface</span><span style="font-size: 10pt">，所谓的</span><span style="font-size: 10pt"> GUI )</span><span style="font-size: 10pt">的应用程序的。因为我们是用的示例程序是简单的基于控制台的</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">应用程序，所以我们选择了</span><span style="font-size: 10pt"> CUI </span><span style="font-size: 10pt">子系统。通常情况下，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">会根据你在开始创建工程时选择的工程模板来自动地设置子系统的选项；</span></li>
    <li><strong><span style="font-size: 10pt">子系统</span></strong><strong><span style="font-size: 10pt"> ID/</span></strong><strong><span style="font-size: 10pt">用户</span></strong><strong><span style="font-size: 10pt"> ID(Subsystem ID/UserID):</span></strong><span style="font-size: 10pt">和子系统项一样，这个选项也是由</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">自动设置的。具体系统对应的</span><span style="font-size: 10pt"> ID </span><span style="font-size: 10pt">为：</span><span style="font-size: 10pt">Windows 3.1</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">Windows 95 </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> Windows NT 3.5 </span><span style="font-size: 10pt">的</span><span style="font-size: 10pt"> ID </span><span style="font-size: 10pt">为</span><span style="font-size: 10pt"> 3.10</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">Windows NT 4 </span><span style="font-size: 10pt">的</span><span style="font-size: 10pt"> ID </span><span style="font-size: 10pt">为</span><span style="font-size: 10pt"> 4.00</span><span style="font-size: 10pt">；</span></li>
    <li><strong><span style="font-size: 10pt">生成连接映射</span></strong><strong><span style="font-size: 10pt">(Generate Link Map):</span></strong><span style="font-size: 10pt">这个选项允许你生成一个文本文件，其中包含了程序中使用到的所有的类和函数的详细信息。当需要通过匹配变量或函数名的地址来调试代码时，这个选项就非常有用了；</span></li>
    <li><strong><span style="font-size: 10pt">生成</span></strong><strong><span style="font-size: 10pt"> SYM </span></strong><strong><span style="font-size: 10pt">文件</span></strong><strong><span style="font-size: 10pt">(Generate SYM File):</span></strong><span style="font-size: 10pt">这个选项允许你在连接过程中生成一个符号文件。大多数的调试器在进行调试时需要一个符号文件来逐步调试你的源代码。我们将在第五课中详细讨论这个内容。此外，你还可以通过选中生成</span><span style="font-size: 10pt"> CV </span><span style="font-size: 10pt">信息项</span><span style="font-size: 10pt">(Generate CV Info item)</span><span style="font-size: 10pt">来生成一个可用于</span><span style="font-size: 10pt"> CodeView </span><span style="font-size: 10pt">的符号文件。</span><span style="font-size: 10pt">CodeView </span><span style="font-size: 10pt">是一个流行的</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">调试工具；</span></li>
    <li><strong><span style="font-size: 10pt">生成</span></strong><strong><span style="font-size: 10pt"> CV </span></strong><strong><span style="font-size: 10pt">信息</span></strong><strong><span style="font-size: 10pt">(Generate CV Info):</span></strong><span style="font-size: 10pt">生成一个可用于</span><span style="font-size: 10pt"> CodeView </span><span style="font-size: 10pt">的符号文件。</span><span style="font-size: 10pt">CodeView </span><span style="font-size: 10pt">是一个流行的</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">调试工具；</span></li>
    <li><strong><span style="font-size: 10pt">命令文件</span></strong><strong><span style="font-size: 10pt">(Command File):</span></strong><span style="font-size: 10pt">这个选项要你选择一个用于指示复杂的连接选项设置的文本文件。该文件称为连接器命令文件。它被使用来指定要导入和导出哪些符号。除非你正在编写一个特殊目的的代码，你才不需要一个连接器文件。</span></li>
</ul>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">正如你所知的，连接器的设置过程是非常复杂的。但是，在多数情况下，你不需要修改连接器的默认设置。</span><span style="font-size: 10pt">Metrowerks </span><span style="font-size: 10pt">公司的开发人员已经帮助你很好地解决了这个问题。</span></div>
<div align="center"><font size="3"><strong>第五课</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>调<span> &nbsp;&nbsp;&nbsp; 试</span></strong></font></div>
<div><strong><span style="color: black">关于调试</span></strong></div>
<div style="margin: 0cm 36pt 0pt"><em><span style="font-size: 10pt">Purging pesky pests proves productive for programmers!</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">调试就是在你的程序代码中找到一个问题并着手去解决它的过程。不管是谁，在编程时都难免出现一些输入或程序逻辑上的错误，一旦出现这种问题，很可能你想破了头也找不到错误在哪。这个问题可能只是一个输入上的小错误或者只是一个变量用错了，因此你很难发现它。但是因为这个错误的存在使得你的程序无法实现预期的功能。有时候会更糟糕，以致你的机器都崩溃了。这时，你就必须借助调试来解决问题。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior </span><span style="font-size: 10pt">带有一个集成的调试器，可以让你在 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">主窗口中打开一个窗口来进行调试工作。使用调试器的方法是，从工程菜单中选择 </span><span style="font-size: 10pt">Enable Debugger </span><span style="font-size: 10pt">项，然后重新编译你的目标文件。完成上述步骤后，你的程序就会在调试窗口中运行，此时你就可以隔离并改正你找到的任何一个问题了。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通常进行调试时总要生成源程序的一个调试目标文件。该目标文件的源文件保持不变，但是需要预先设置置一些选项才能产生该程序的调试版本。通过点击工程窗口的弹出菜单中的调试目标文件，你就可以进入调试状态。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-1: </span></em><em><span style="font-size: 7.5pt">调试器界面</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">图</span><span style="font-size: 10pt"> 5-1</span><span style="font-size: 10pt">显示了</span><span style="font-size: 10pt"> Hello World </span><span style="font-size: 10pt">这个程序在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">调试器中进行调试时的情况。为了能够更方便地演示调试器的工作过程，我们在程序中添加了一小段循环代码</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">其中使用了</span><span style="font-size: 10pt"> i</span><span style="font-size: 10pt">、</span><span style="font-size: 10pt">x </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> y </span><span style="font-size: 10pt">等三个变量</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。调试器允许对代码执行单步逐行调试。当你在代码中移动时，你还可以查看程序中所有变量的值。在这种&ldquo;慢速移动</span><span style="font-size: 10pt">(slow motion)</span><span style="font-size: 10pt">&rdquo;的方式下调试程序，你可以非常清晰地查看到代码的运行情况并很容易地解决问题。</span></div>
<div style="margin: 0cm 36pt 0pt"><em><span style="font-size: 10pt">但实际情况是，不是所有的问题都很容易解决的。有些问题就有可能要花费你长达数周的时间去解决。不管是经验多么丰富的编程老手，同样不可避免地要遇到这样的问题。作为一个初学者，你更容易遇到这样的问题，但是，你千万别被这种情况吓倒。请记住，从错误中学习，你能学到更多的东西。</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">请注意在调试器窗口左上角的那些按钮，它们是用于帮助你进行调试工作的。这些按钮从左到右分别是：运行程序</span><span style="font-size: 10pt">(Run Program)</span><span style="font-size: 10pt">、停止</span><span style="font-size: 10pt">(Stop)</span><span style="font-size: 10pt">、退出</span><span style="font-size: 10pt">(Kill (Quit))</span><span style="font-size: 10pt">、跳过</span><span style="font-size: 10pt">(Step Over)</span><span style="font-size: 10pt">、转入</span><span style="font-size: 10pt">(Step Into)</span><span style="font-size: 10pt">和转出</span><span style="font-size: 10pt">(Step Out)</span><span style="font-size: 10pt">。最后两个命令按钮是让你决定在单步调试程序时，如果遇到一个函数，是否要进入函数内部进行代码调试。或者你也可以使用跳过</span><span style="font-size: 10pt">(Step Over)</span><span style="font-size: 10pt">命令让该函数一次执行完毕，而不进入函数体中单步调试函数的代码，这样可以节省一些时间。如果你不能肯定函数是否正确无误，那么你可以转入</span><span style="font-size: 10pt">(step into)</span><span style="font-size: 10pt">该函数体内部对其进行单步调试。对于初学者，你应该单步调试每一个函数，至少可以练练手嘛！</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">图</span><span style="font-size: 10pt"> 5-1 </span><span style="font-size: 10pt">所示的调试窗口包含三个主要部分：</span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">栈窗格</span></strong><strong><span style="font-size: 10pt">(The Stack pane)</span></strong><strong><span style="font-size: 10pt">：</span></strong><span style="font-size: 10pt">位于左上方的窗格是显示调用栈</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">也叫做调用栈的记录</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">的区域。当你在单步调试源码的过程中调用了多个函数时，在这个区域就显示出调试到达当前状态之前调用过的函数名清单。这个清单会随着你的调试过程，根据你是否转入函数内部的情况随时增减；</span></li>
    <li><strong><span style="font-size: 10pt">变量窗格</span></strong><strong><span style="font-size: 10pt">(The Variables pane):</span></strong>&nbsp;<span style="font-size: 10pt">位于右上方的窗格是显示变量名和其值的区域。其中显示的是各个变量的名字和它们的值，而且还可以依据变量的类型让你查看</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">或修改</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">这些数据。在图</span><span style="font-size: 10pt">5-1</span><span style="font-size: 10pt">中显示的</span><span style="font-size: 10pt"> Hello World x86 </span><span style="font-size: 10pt">程序这个例子中，有四个变量：</span><span style="font-size: 10pt">c</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">i</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">x </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> y</span><span style="font-size: 10pt">。当你在代码中执行单步调试时，这些变量的值就会根据程序执行的过程实时地更新。例如，在调试过程中，你可以注意到后三个变量是如何取得它们的值的</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">这些值是在循环代码中赋给这些变量的</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，而变量</span><span style="font-size: 10pt"> c </span><span style="font-size: 10pt">显示的是一个无意义的值</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">因为你还没有给</span><span style="font-size: 10pt"> getchar() </span><span style="font-size: 10pt">输入任何值</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。你可以使用这个窗格来发现不正常的变量值，从而发现程序设计上的错误这对于程序的调试成功，非常关键；</span></li>
    <li><strong><span style="font-size: 10pt">源代码窗格</span></strong><strong><span style="font-size: 10pt">(The Source pane)</span></strong><strong><span style="font-size: 10pt">：</span></strong><span style="font-size: 10pt">位于下方的窗格显示了</span><span style="font-size: 10pt"> Hello World x86 </span><span style="font-size: 10pt">这个程序的</span><span style="font-size: 10pt"> C </span><span style="font-size: 10pt">语言源代码，它也可以用来显示该代码的汇编语言版本。随着调试的深入进行，仅仅是程序的</span><span style="font-size: 10pt"> C </span><span style="font-size: 10pt">语言代码可能不能提供足够的调试信息，这是你就需要查看该程序的汇编语言代码。你可以通过该窗口下端的弹出菜单来选择查看程序的源代码、汇编代码或者两者的混合显示。</span></li>
</ul>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">你可能已经注意到在源代码窗格左边的红色停止标记，该标记表示这是一个断点，它用于告诉调试器在此处停止执行程序。此功能可以帮助你很方便地快速到达程序中地某一位置，然后从此位置处开始调试程序。当你设置了一个断点，调试器运行到断点所在的行就停止下来，等待你的控制命令。在某行程序左边显示的蓝色小箭头是当前程序的计数器，它表示指向的程序行为即将要执行到的语句。在图</span><span style="font-size: 10pt">5-1</span><span style="font-size: 10pt">中，我们已经设置了一个断点以便程序执行到完源代码中的循环块后在第二个输出语句前停下来。设置断点的操作也很简单，只需在你希望调试器停止的程序行的左端点一下鼠标即可。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">下面我们来看看关于</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">调试器的一些参数设置。</span></div>
<div><font size="3"><strong><span style="color: black">全局调试器参数设置</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通过选择编辑菜单中的&ldquo;</span><span style="font-size: 10pt">Preferences</span><span style="font-size: 10pt">&rdquo;项，可以看见</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">调试器有许多全局的参数设置。</span></div>
<div><font size="3"><strong>设置内容</strong></font></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-2: </span></em><em><span style="font-size: 7.5pt">调试器全局参数设置显示</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">设置显示面板</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">见图</span><span style="font-size: 10pt">5-2)</span><span style="font-size: 10pt">包含了一些决定调试器窗口上如何显示信息的参数设置。当你刚开始使用调试器时，你可以在这里把调试器窗口上的某些文字设置得大一些或小一些，或者用一些特殊的颜色来显示它们。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">颜色设置允许你选择在源代码中用于突显观察点</span><span style="font-size: 10pt">(watchpoints)</span><span style="font-size: 10pt">和变量名的文字颜色。这种设置非常有用，可以帮助你在调试代码时很容易地观察到观察点或变量值的变化。观察点可用来帮助你在整个程序中跟踪某个值并将其显示在一个窗口中。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">其它设置的用途都解释得很明白了，你也不需要去更它们，默认设计就可以了。当你对调试器了解得更多了一些时，你才可能会的想去修改这些设置。</span></div>
<div><font size="3"><strong>关于视窗的设置</strong></font></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-3: </span></em><em><span style="font-size: 7.5pt">关于视窗的设置</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在调试程序的过程中，你会发现桌面上很会就挤满了许多打开的窗口。关于视窗的设置</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">见图</span><span style="font-size: 10pt">5-3)</span><span style="font-size: 10pt">允许你设定在调试中隐藏或显示某些特定的窗口来管理这些窗口。默认的设置是隐藏非调试用的窗口，这在大多数情况下就可以了，不必修改它。</span></div>
<div><font size="3"><strong>全局设置</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">全局设置窗格</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如图</span><span style="font-size: 10pt">5-4</span><span style="font-size: 10pt">所示</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">包含了一些用于控制调试器操作方式的选项。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-4: </span></em><em><span style="font-size: 7.5pt">全局设置</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">调试过程中缓存修改后的文件这一设置是用于决定修改后的文件需要缓存多长时间用的。缓存文件能够提高调试器的速度，但是要牺牲一些磁盘空间。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">其余的设置解释得很清楚了。如果你只是一个初学者，那么默认设置就可以了。</span></div>
<div><font size="3"><strong>远程连接</strong></font></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-5: </span></em><em><span style="font-size: 7.5pt">远程连接</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">最后是远程连接设置</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">见图</span><span style="font-size: 10pt">5-5)</span><span style="font-size: 10pt">。该设置面板用于设置通过一个</span><span style="font-size: 10pt"> TCP/IP </span><span style="font-size: 10pt">网络进行远程调试。这是一些高级设置，作为初学者，使用默认设置就可以了。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">至于</span><span style="font-size: 10pt"> Java </span><span style="font-size: 10pt">设置和</span><span style="font-size: 10pt"> Java </span><span style="font-size: 10pt">调试面板用于使用</span><span style="font-size: 10pt"> Java </span><span style="font-size: 10pt">语言进行编程的情况的，本课程不涉及这个内容。你可以学习一些相应的课程。</span></div>
<div><font size="3"><strong><span style="color: black">目标文件和工程特定的调试器参数设置</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">以下是关于被调试的目标文件和工程的设置项。当在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">的工程窗口的目标文件标签中有一个目标文件被选中时，你再选择编辑菜单中的工程名设置</span><span style="font-size: 10pt">(Project Name Settings)</span><span style="font-size: 10pt">项即可看到这个设置窗口。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-6: </span></em><em><span style="font-size: 7.5pt">目标文件和工程调试器设置</span></em></div>
<div><strong><font size="3">调试器设置</font></strong></div>
<ul style="margin-top: 0cm" type="disc">
    <li><strong><span style="font-size: 10pt">重定位后的库</span></strong><strong><span style="font-size: 10pt">...</span></strong><strong><span style="font-size: 10pt">的位置</span></strong><strong><span style="font-size: 10pt">(Location of Relocated Libraries, etc)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">如果你正在调试的文件被移到其它位置了，或者你正在通过一个</span><span style="font-size: 10pt"> TCP/IP </span><span style="font-size: 10pt">网络来进行远程调试，你就必须将这些文件所在的目录输入到这个文本框中；</span></li>
    <li><strong><span style="font-size: 10pt">在应用程序启动时在临时断点处停止</span></strong><strong><span style="font-size: 10pt">(Stop at temp breakpoint on application launch)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">默认情况下，这个选项在程序的起始位置中断调试器的运行。但你也可以设置为可在任何断点处中断；</span></li>
    <li><strong><span style="font-size: 10pt">自动查找目标库</span></strong><strong><span style="font-size: 10pt">(Auto-target Libraries)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">选中这个选项可以自动地访问库。此选项用于正在调试的代码是一个库的一部分时，当你调试这些代码时，调试器将&ldquo;做应做的事&rdquo;</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">例如装载库并调用任何初始化函数</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">；</span></li>
    <li><strong><span style="font-size: 10pt">记录系统消息</span></strong><strong><span style="font-size: 10pt">(Log System Messages)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">这个选项用于强制将所有的系统消息写入一个记录文件中。当你遇到代码导致系统崩溃，并因系统崩溃又看不到屏幕显示时，就很有用了。当你重启机器后，你可以从记录文件中查看导致系统崩溃的消息。特别是今后你调试一些大型程序时，记录文件就很有用了，所以一定要学会读懂记录文件！</span></li>
    <li><strong><span style="font-size: 10pt">数据更新时间间隔</span></strong><strong><span style="font-size: 10pt">(Data Update Interval)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">选中这个选项并给它设置一个值，这样你就可以决定数据查看</span><span style="font-size: 10pt">(data view)</span><span style="font-size: 10pt">多长时间更新一次。数据查看更新得越频繁，调试器显示的数据值就越新；</span></li>
    <li><strong><span style="font-size: 10pt">缓存运行中的符号文件</span></strong><strong><span style="font-size: 10pt">(Cache symbolics between runs)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">在调试器运行时，符号文件</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">在编译过程中产生的一种文件</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">将被缓存起来。这可以提高调试的进程；</span></li>
    <li><strong><span style="font-size: 10pt">在观察点处停止</span></strong><strong><span style="font-size: 10pt">(Stop at Watchpoints)</span></strong><span style="font-size: 10pt">: </span><span style="font-size: 10pt">选中此项，当观察点值为真时就中断调试。观察点和断点一样是很有用的。不同的是，断点每次都是在一个特定的代码行处停止下来，而观察点是监视一个变量或内存的一块区域，当此被观察的对象发生改变时，它就中断调试过程。这和</span><span style="font-size: 10pt"> VC </span><span style="font-size: 10pt">中的条件断点相似，都是在设定的条件被满足时中断调试过程的。这是一个很有用的调试工具。</span></li>
</ul>
<div><strong><span style="font-size: 10pt">x86 </span></strong><font size="3"><strong>异常</strong><strong>(Exceptions)</strong></font></div>
<div align="center"><em><span style="font-size: 7.5pt">图 </span></em><em><span style="font-size: 7.5pt">5-7:&nbsp; x86 </span></em><em><span style="font-size: 7.5pt">出错信息面板</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">当你调试有问题的代码时，</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">调试器会截取到由程序的</span><span style="font-size: 10pt"> bug </span><span style="font-size: 10pt">引起的某些奇怪的操作</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">即所谓的</span><span style="font-size: 10pt">异常&mdash;&mdash;</span><span style="font-size: 10pt">Exceptions)</span><span style="font-size: 10pt">。</span><span style="font-size: 10pt"> IDE </span><span style="font-size: 10pt">会将这些异常传递给一个特殊的代码&mdash;&mdash;一个被称之为处理器的东西&mdash;&mdash;由它来处理这些异常问题。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">但是，对于大多数的异常，调试器只是简单地中断它的工作而已。为什么会这样呢？</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">如果你正在做一个高级开发，例如开发一个系统库或一个设备驱动程序，你可能想测试一下这些代码是如何处理这些异常的。只有调试器不截取这些异常时，你才能这么做。如果为了一些特定的原因，你希望调试器抓住某些特定异常发生时的控制</span><span style="font-size: 10pt">(&quot;seize control of the moment&quot; for specific exceptions) </span><span style="font-size: 10pt">，你就应该在这个设置面板上做一些设置。在该面板上显示的异常是</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">的集成开发环境可以处置的情况。点击那些你希望由调试器来处理的异常情况，然后点击&ldquo;保存&rdquo;按钮保存设置。就像前面提到的，这是很高级的编程设置，因此我们在这将不作详细讨论。总之，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的调试器是一个非常先进的，而且很易于使用的附件。如果你学好了调试器的使用，它将会成为你开发软件的最重要的一个工具。</span></div>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">另外还有&ldquo;其它的可执行程序&rdquo;和&ldquo;远程调试&rdquo;设置面板，它们是针对高级用户设置的，本课程不打算再作介绍。如果你需要同时调试多个可执行程序或通过</span><span style="font-size: 10pt"> TCP/IP </span><span style="font-size: 10pt">网络来调试程序的话，你可以自行参看这几个设置面板。</span></div>
<div align="center"><font size="3"><strong>第六课</strong>&nbsp;&nbsp;&nbsp; <strong>定<span> &nbsp;&nbsp;&nbsp; 制</span></strong></font></div>
<div><strong><span style="color: black">概 </span></strong><strong>&nbsp;</strong><strong><span style="color: black">述</span></strong><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">这将是最简单的一课，但它却能够帮助帮助你更好地组织你的思想和开展工作。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt">正如我们在第一课中学到的，可以有许多中方式来为手头某个特定的任务定制 </span><span style="font-size: 10pt">CodeWarrior</span><span style="font-size: 10pt">。你可以定制 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的外观和许多设置项，以便使得编译、连接和调试你的程序变得更快、更简单。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">下面我们来看看可用于帮助你更有效地使用 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的定制选项。因为定制 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">会改变 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">的所有行为，所以我们可以想到在编辑菜单下找到这些设置项。在那儿你将找到选择、命令和键绑定</span><span style="font-size: 10pt">(Key Bindings)</span><span style="font-size: 10pt">等菜单。点击其中的命令项就会显示定制 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">命令设置的窗口。定制 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">命令的面板包含两个主标签页。命令标签页允许你很容易的定制出现在每个 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">菜单中的命令。通过该标签页你也可以修改在内置的文本编辑器中使用的命令，例如选择文本和移动光标等命令。在这个设置窗口中，你还可以创建任何用于触发某个菜单命令项的组合键</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">也称之为键绑定&mdash;&mdash;</span><span style="font-size: 10pt">key binding)</span><span style="font-size: 10pt">，以此来启动一个应用程序，或者执行一个脚本。当然，你也可以设定一个某个命令项是否出现在一个菜单中。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">定制 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">命令的面板中的另一个标签页是工具条项目标签页，在这个标签页中你可以看到在 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的工具条中显示的项目，例如显示在每个文本编辑器窗口上方</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">或下方，取决于你的参数设置</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在工具条项目标签页中，你只需点击一个工具条图标然后把它拖到主菜单下面的工具条或者文本编辑器窗口的工具条中，就可以往相应的工具条中增加一个命令。还可以把工具条中的一个图标拉到工具条的最后。从 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的窗口菜单中的工具条子菜单中选择重设窗口的工具条</span><span style="font-size: 10pt">(Reset Window Toolbar) </span><span style="font-size: 10pt">或重设浮动工具条菜单项，还可以重新设置该工具条。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">在大多数情况下，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的默认设置就可以满足你的要求了。偶尔你也可能发现一个通过改变一个菜单或工具条的方式来自动完成一些任务。关于 </span><span style="font-size: 10pt">Codewarrior </span><span style="font-size: 10pt">的定制，你可以参考它的在线文档获得更多的信息。<br />
<br />
</span><font size="3"><strong><span style="color: black">CodeWarrior </span></strong><strong><span style="color: black">定制示例</span></strong></font><span style="color: black"><br />
</span><span style="font-size: 10pt"><br />
</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">通过定制 </span><span style="font-size: 10pt">CodeWarrior</span><span style="font-size: 10pt">，你可以增强你的工作环境和提高工作效率。 </span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">除了对菜单和工具条的简单修改之外，你可能还想只需点击一个图标或键入一个组合键就可以执行一个脚本或启动一个应用程序。有时当你正在参与一个非常庞大的开发项目的时候，需要做一些定制工作来解决自动设置带来的混乱问题。例如，你可以创建一个脚本来完成以下这些工作： </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><span style="font-size: 10pt">自动删除编译过程中产生的多余的文件；</span></li>
    <li><span style="font-size: 10pt">将输出文件复制到一个本地或网络上的目录中以做备份；</span></li>
    <li><span style="font-size: 10pt">为你的工程创建一个安装应用程序。</span></li>
</ul>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">对于 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">用户而言，可以通过 </span><span style="font-size: 10pt">VBScript</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">Perl</span><span style="font-size: 10pt">或其它使用通用对象模型</span><span style="font-size: 10pt">(Common Object Model</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">COM)</span><span style="font-size: 10pt">接口的脚本语言来驱动 </span><span style="font-size: 10pt">CodeWarrior Pro 5 IDE </span><span style="font-size: 10pt">完成一系列复杂的操作。如果使用 </span><span style="font-size: 10pt">VBscript</span><span style="font-size: 10pt">，你还需要一个可以执行 </span><span style="font-size: 10pt">VBScript </span><span style="font-size: 10pt">的的应用程序</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">如 </span><span style="font-size: 10pt">Internet Explorer 5)</span><span style="font-size: 10pt">，或者是一个 </span><span style="font-size: 10pt">Scripting Host </span><span style="font-size: 10pt">工具&mdash;&mdash;可以从以下网址下载 </span><span style="font-size: 10pt"><a target="new" href="http://msdn.microsoft.com/scripting/windowshost/"><font color="#000000">http://msdn.microsoft.com/scripting/windowshost/</font></a></span><span style="font-size: 10pt">。 </span>&nbsp;</div>
<div><span style="font-size: 10pt">&nbsp;&nbsp; </span><span style="font-size: 10pt">下面的 </span><span style="font-size: 10pt">VBScript </span><span style="font-size: 10pt">脚本用于指导 </span><span style="font-size: 10pt">CodeWarrior IDE </span><span style="font-size: 10pt">删除当前工程中的所有目标</span><span style="font-size: 10pt">(object)</span><span style="font-size: 10pt">文件，以便执行一个&ldquo;干净的构建</span><span style="font-size: 10pt">(build)</span><span style="font-size: 10pt">&rdquo;</span><span style="font-size: 10pt">，然后再执行构建工作</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">编译和连接操作</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。该脚本还打开一个编辑器窗口来显示操作结果</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">成功或失败的</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">的总结。这个脚本是有点长，但设计得很好，因为其中包含了许多用于错误检查的代码。 </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span><span style="font-size: 10pt">文件名：</span><span style="font-size: 10pt">Build.vbs</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span><span style="font-size: 10pt">作者： </span><span style="font-size: 10pt">Jim Trudeau, Metrowerks</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' </span><span style="font-size: 10pt">以及版权声明信息</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; option explicit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'</span><span style="font-size: 10pt">所有的变量都必须进行声明</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim CW <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim project &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">默认的工程<br />
</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim textDocument&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">用于保存报告的文本文档 <br />
</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim textEngine &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">用于处理文本的对象<br />
</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim eol &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">行尾字符格式<br />
</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim result &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">返回的值</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">eol = chr(13) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">设置行尾字符</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'</span><span style="font-size: 10pt">创建 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的一个实例<br />
</span><span style="font-size: 10pt">set CW = CreateObject(&quot;CodeWarrior.CodeWarriorApp&quot;)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'</span><span style="font-size: 10pt">创建一个文本文档并获得其引擎</span><span style="font-size: 10pt">(Engine)<br />
set textDocument = CW.OpenUntitledTextDocument() <br />
set textEngine = textDocument.TextEngine</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'</span><span style="font-size: 10pt">得到默认的工程<br />
</span><span style="font-size: 10pt">set project = CW.DefaultProject</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'</span><span style="font-size: 10pt">错误控制<br />
</span><span style="font-size: 10pt">if TypeName(project) = &quot;Nothing&quot; then <br />
textEngine.InsertText(&quot;Script operates on default project.&quot; &amp;eol) &nbsp;&nbsp;&nbsp; textEngine.InsertText(&quot;There must be at least one open project.&quot; &amp;eol) <br />
else <br />
dim target&nbsp;&nbsp; '</span><span style="font-size: 10pt">当前目标<br />
</span><span style="font-size: 10pt">dim buildmessages '</span><span style="font-size: 10pt">错误和警告</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">获得当前目标<br />
</span><span style="font-size: 10pt">set target = project.GetCurrentTarget</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">textEngine.InsertText(&quot;Build Information&quot; &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'</span><span style="font-size: 10pt">显示名字<br />
</span><span style="font-size: 10pt">result = target.name</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">textEngine.InsertText(&quot;Building target &quot; &amp;result &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">删除所有的对象代码目标<br />
</span><span style="font-size: 10pt">RemoveObjectCode true</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">获得构建代码后的消息<br />
</span><span style="font-size: 10pt">set buildMessages = target.BuildAndWaitToComplete</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">ProcessMessages (buildMessages) <br />
end if</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'========================================================= ' ProcessMessages - get errors and warnings, process them ' receives build messages '=========================================================</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">sub ProcessMessages (messages)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">dim result&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '</span><span style="font-size: 10pt">返回值<br />
</span><span style="font-size: 10pt">dim messageList '</span><span style="font-size: 10pt">消息收集</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">获得错误的数量<br />
</span><span style="font-size: 10pt">result = messages.ErrorCount</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">if result = 0 then textEngine.InsertText(eol &amp;&quot;Build Succeeded.&quot; &amp;eol) <br />
else textEngine.InsertText(eol &amp;&quot;!!!BUILD FAILED!!!&quot; &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">显示错误的数量<br />
</span><span style="font-size: 10pt">textEngine.InsertText(&quot;Number of errors: &quot; &amp;result &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">获得错误清单<br />
</span><span style="font-size: 10pt">set messageList = messages.Errors</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">处理错误<br />
</span><span style="font-size: 10pt">ProcessMessageList (messageList) <br />
end if</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">检测是否有警告信息<br />
</span><span style="font-size: 10pt">result = messages.WarningCount</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">显示数量<br />
</span><span style="font-size: 10pt">textEngine.InsertText(&quot;Number of warnings: &quot; &amp;result &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">取得警告信息并处理之<br />
</span><span style="font-size: 10pt">if result then <br />
'*** </span><span style="font-size: 10pt">获得警告信息清单<br />
</span><span style="font-size: 10pt">set messageList = messages.Warnings</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">处理警告信息<br />
</span><span style="font-size: 10pt">ProcessMessageList (messageList) <br />
end if</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">end sub</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'========================================================= ' ProcessMessagelist - loop through messages, report info ' receives message collection, could be errors or warnings '=========================================================</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">sub ProcessMessageList (messageList)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">dim result '</span><span style="font-size: 10pt">返回值<br />
</span><span style="font-size: 10pt">dim index '</span><span style="font-size: 10pt">循环计数器<br />
</span><span style="font-size: 10pt">dim message '</span><span style="font-size: 10pt">个人信息</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">遍历消息清单<br />
</span><span style="font-size: 10pt">for index = 0 to messageList.Count-1 <br />
'*** </span><span style="font-size: 10pt">获得个人信息<br />
</span><span style="font-size: 10pt">set message = messageList.Item(index)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">获得消息文本</span><span style="font-size: 10pt"><br />
</span><span style="font-size: 10pt">result = message.MessageText</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">'*** </span><span style="font-size: 10pt">显示消息文本</span><span style="font-size: 10pt"><br />
</span><span style="font-size: 10pt">textEngine.InsertText(result &amp;eol)</span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">****</span><span style="font-size: 10pt">在错误中忽略一行</span><span style="font-size: 10pt">(skip a line between errors )<br />
textEngine.InsertText(eol) <br />
next </span></div>
<div style="margin: 0cm 36pt 0pt"><span style="font-size: 10pt">end sub</span></div>
<div style="text-indent: 14.25pt"><span style="font-size: 10pt">因为使用了微软公司的 </span><span style="font-size: 10pt">OLE/COM </span><span style="font-size: 10pt">查看器工具，这个 </span><span style="font-size: 10pt">IDE </span><span style="font-size: 10pt">支持许多 </span><span style="font-size: 10pt">COM </span><span style="font-size: 10pt">对象。一个脚本语言可以使用这些对象来与 </span><span style="font-size: 10pt">CodeWarrior IDE </span><span style="font-size: 10pt">进行通信。关于 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">定制与脚本机制，还有很多优秀的功能，但在这里就不详述了，因为 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">把这些功能实现得非常好。打开上面所描述到得窗口自己看看吧！当你熟练使用了 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的一些功能之后，你会发现它是非常的易用！</span></div>
<div align="center"><font size="3"><strong>第七课</strong>&nbsp;&nbsp;<strong>库 和 Microsoft Foundation Classes (MFC)</strong></font>&nbsp;</div>
<div><strong><span style="color: black">库</span></strong></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">库是什么？这是一个你必须知道如何回答的问题！一个库就是一个包含了你程序运行时需要调用的函数的文件。在库中提供的典型函数有：文件和屏幕的 </span><span style="font-size: 10pt">I/O </span><span style="font-size: 10pt">函数，内存管理服务，</span><span style="font-size: 10pt">3-D </span><span style="font-size: 10pt">图形显示以及科学计算函数。使用库可以缩短你的开发时间并简化你的应用程序。在开发程序当中，你会经常地使用到库。以下是几种在编程中使用库的方法： </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><span style="font-size: 10pt">将你需要用到的函数写在一个源文件中，然后把它编译成为一个库或</span><span style="font-size: 10pt">DLL</span><span style="font-size: 10pt">；</span></li>
    <li><span style="font-size: 10pt">使用别人提供的库；</span></li>
    <li><span style="font-size: 10pt">使用一个其他人提供的共享库</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">或</span><span style="font-size: 10pt">DLL)</span><span style="font-size: 10pt">。</span></li>
</ul>
<div><font size="3"><strong>编写你自己的库或 </strong><strong>DLL</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">第一种使用库的方法很简单。你只需在一个 </span><span style="font-size: 10pt">C </span><span style="font-size: 10pt">或 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">源文件中写入源代码，然后编译、连接并执行它。这是我们在本课程中早已学到的知识。就这样你就可以创建你自己的一个库，就这么简单！</span></div>
<div><font size="3"><strong>使用别人的库</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">使用别人提供的库稍稍有些不同。由第三方开发商提供的库通常包括以下几个文件：库文件</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">通常是以 </span><span style="font-size: 10pt">.lib </span><span style="font-size: 10pt">为后缀名的文件</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，一个头文件</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">后缀名为 </span><span style="font-size: 10pt">.h) </span><span style="font-size: 10pt">以及</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">我们希望有但不一定有</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">一些文档</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">后缀名为</span><span style="font-size: 10pt">.doc)</span><span style="font-size: 10pt">。头文件是用于让编译器将你的程序中使用的函数与库中的函数匹配起来的。你只需将头文件包括到你的源文件中，然后就可以象调用操作系统的函数一样来调用库函数了。在大多数情况下，通常将 </span><span style="font-size: 10pt">.h </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">.lib </span><span style="font-size: 10pt">的文件放置于源文件目录中，就像 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">定义的一样。这个路径通常在你的工程文件所在的目录，或者其下的子目录中。需要注意的是，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">提供的某些特定的库，例如它的 </span><span style="font-size: 10pt">MSL</span><span style="font-size: 10pt">，就不是放在你的工程所在的目录中。实际上，</span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">有一个特定的存取路径，叫做 </span><strong><span style="font-size: 10pt">system paths,</span></strong><span style="font-size: 10pt">它指向 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">自带的库和头文件存放的目录。</span></div>
<div><font size="3"><strong>使用一个共享库</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">第三方厂商将库函数与它们的产品打包起来发行，而不是以源文件的方式发行这些库。如果你是一个开发商，使用这样的方式来发行你的库会更安全一些，特别是你希望由此来保护你的知识产权时。但是这种方法也存在一个问题，就是如果在库中存在一个 </span><span style="font-size: 10pt">bug </span><span style="font-size: 10pt">的话，用户是没办法对之进行修改的，只能从开发商那里取得一个修正后的版本。但是这做起来也有许多困难。</span></div>
<div><font size="3"><strong>共享的 </strong><strong>DLL </strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; DLL </span><span style="font-size: 10pt">和库文件非常相似，两者之间唯独的不同就是库文件通常都会被编译并连接到你的应用程序中，而 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">则是存放在你的系统目录下或者是在编译后的应用程序的目录下的一个独立的文件。当应用程序运行时，它会自己去找到该 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">并使用它的服务。</span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">文件的后缀名为 </span><span style="font-size: 10pt">.dll</span><span style="font-size: 10pt">。</span></div>
<div><font size="3"><strong>使用共享的</strong><strong>DLLs </strong><strong>的好处</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; DLL </span><span style="font-size: 10pt">的优点就是它能够被共享。那么，共享的好处在哪里呢？首先，可以让多个应用程序使用一个 </span><span style="font-size: 10pt">DLL</span><span style="font-size: 10pt">。当几个程序都使用一个占用很大磁盘和内存空间的 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">时，就很有用了。另外，如果一个 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">包含了一个 </span><span style="font-size: 10pt">bug</span><span style="font-size: 10pt">，然后被修正了，那么所有使用这个 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">的程序都会被自动更新，这样就可以大大地节约你的开发时间。那么哪种库应该由多个应用程序共享呢？比如操作系统中的每一个视窗就是使用共享的 </span><span style="font-size: 10pt">DLL </span><span style="font-size: 10pt">得来的。</span></div>
<div><font size="3"><strong>使用共享 </strong><strong>DLL </strong><strong>需要注意的地方</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior IDE </span><span style="font-size: 10pt">的 </span><span style="font-size: 10pt">CD-ROM </span><span style="font-size: 10pt">中有许多库，在因特网上还有成千上万的库。记住，当你使用第三方厂商的库时，千万要先查查毒。这就如同出门前要关门一样的有必要。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; CodeWarrior </span><span style="font-size: 10pt">自带的库分为两类。一个是 </span><span style="font-size: 10pt">MSL</span><span style="font-size: 10pt">，它提供 </span><span style="font-size: 10pt">ANSI C/C++ </span><span style="font-size: 10pt">的标准函数。</span><span style="font-size: 10pt">MSL </span><span style="font-size: 10pt">已经被移植到许多平台上了，因此可以在 </span><span style="font-size: 10pt">Windows</span><span style="font-size: 10pt">，</span><span style="font-size: 10pt">Mac OS </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">Solaris </span><span style="font-size: 10pt">系统中使用它的函数。另一个是供特定平台使用的库。例如，在 Windows 版的光盘中，你可以发现提供了使用 </span><span style="font-size: 10pt">Windows APIs </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">库的</span><span style="font-size: 10pt">Windows 32 </span><span style="font-size: 10pt">支持库，它提供了编写面向对象的 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">应用程序的框架。随着你的编程经验的增长，你将发现这些特定库的更多的用途。</span></div>
<div><font size="3"><strong><span style="color: black">MFC</span></strong><strong><span style="color: black">是什么</span></strong><strong><span style="color: black">?</span></strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; Microsoft Foundation Classes (MFC) </span><span style="font-size: 10pt">提供了快速开发 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">应用程序的函数集。虽然你已经可以自由地直接调用 </span><span style="font-size: 10pt">Win32 APIs</span><span style="font-size: 10pt">，但使用 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">会更简单一些，因为 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">提供了诸如创建一个窗口或者使用智能默认设置和错误检查代码来编写文件这样的基本服务。</span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">可以在 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">版的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">光盘中找到，但不一定是最新的版本。你可以查看 </span><span style="font-size: 10pt">Metrowerks </span><span style="font-size: 10pt">的帮助页面来获得相关信息，因为微软公司会为 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">的发行版本提供一些升级补丁。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">对于特定平台，比如</span><span style="font-size: 10pt">Macintosh </span><span style="font-size: 10pt">的开发者可以使用 </span><span style="font-size: 10pt">Metrowerks </span><span style="font-size: 10pt">自己的 </span><span style="font-size: 10pt">PowerPlant </span><span style="font-size: 10pt">类库。</span><span style="font-size: 10pt">PowerPlant </span><span style="font-size: 10pt">是为编写 </span><span style="font-size: 10pt">Mac </span><span style="font-size: 10pt">应用程序而设计的面向对象的应用程序框架。我们在本课程中并不打算讨论 </span><span style="font-size: 10pt">PowerPlant</span><span style="font-size: 10pt">，但你应知道，它与 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">在许多方面是类似的。你在这里学到的知识也将帮助你理解 </span><span style="font-size: 10pt">PowerPlant</span><span style="font-size: 10pt">。我们讨论 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">时，其中的许多概念也可以应用到 </span><span style="font-size: 10pt">PowerPlant </span><span style="font-size: 10pt">上。</span></div>
<div style="margin: 0cm 36pt 0pt"><strong><span style="font-size: 10pt">注意</span></strong><strong><span style="font-size: 10pt">:</span></strong><span style="font-size: 10pt">在 </span><span style="font-size: 10pt">Macintosh </span><span style="font-size: 10pt">版的 </span><span style="font-size: 10pt">CodeWarrior </span><span style="font-size: 10pt">光盘中也有一个 </span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">的库文件，但不像 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">版的光盘，这里不包含源代码。使用 </span><span style="font-size: 10pt">MFC</span><span style="font-size: 10pt">，你可以编写跨平台的代码，还可以同时为 </span><span style="font-size: 10pt">Macintosh(</span><span style="font-size: 10pt">使用 </span><span style="font-size: 10pt">PowerPlant) </span><span style="font-size: 10pt">和 </span><span style="font-size: 10pt">PC(</span><span style="font-size: 10pt">使用 </span><span style="font-size: 10pt">MFC) </span><span style="font-size: 10pt">编译这个代码。是不是很酷？</span></div>
<div><font size="3"><strong>应用程序框架</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">就像前面提到过的一样，</span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">是一个应用程序框架。也就是说，</span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">是一个源代码或库格式的</span><span style="font-size: 10pt"> C++ </span><span style="font-size: 10pt">类集。使用这个框架可以在较短时间内创建一个支持高级操作系统功能的完整的应用程序。此外，</span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">还包含了用以构造你的用户界面的工具。这些工具，特别是图象编辑器、对话框编辑器和资源编译器，能够帮助你构造用户界面中的图形元素</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">在本课最后一节中将解释如何安装这些有用的组件</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">。一个应用程序框架只涉及到应用程序的标准用户界面，而与该应用程序的特有的内容无关。换句话说，这个框架能够帮助你构造一个功能强大的用户界面，把你的时间节省下来以便让你有更多时间去编写实现应用程序目的的其它函数。因此你不必担心会花很多时间来创建一个和其它一些运行在操作系统环境中具有同样 </span><span style="font-size: 10pt">Windows </span><span style="font-size: 10pt">化界面的应用程序，因为你只需去运用那些库就可以达到这些目的了。</span></div>
<div align="center"><em><span style="font-size: 7.5pt">图</span></em><em><span style="font-size: 7.5pt"> 7-1 MFC </span></em><em><span style="font-size: 7.5pt">的用户界面构造器</span></em></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">应用程序框架还能处理分发消息</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">例如用户击键的动作、鼠标点击、绘画消息等等</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">到应用程序中的许多按钮、列表、窗口和控件上。这个功能帮助你能够集中注意力到实现应用程序的功能而不是界面上，把那些创建界面的工作留给应用程序框架吧。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">应用程序框架提供了许多超过老式风格的</span><span style="font-size: 10pt"> roll-your-own </span><span style="font-size: 10pt">方法。首先，这些代码是成熟和经过严格测试的。每天都有成百上千的开发者使用</span><span style="font-size: 10pt"> MFC </span><span style="font-size: 10pt">来开发应用程序。每当</span><span style="font-size: 10pt"> Windows </span><span style="font-size: 10pt">操作系统增加了一些新的功能的时候，</span><span style="font-size: 10pt">MFC </span><span style="font-size: 10pt">也会不断地被升级，你可以通过使用新版本的</span><span style="font-size: 10pt"> MFC </span><span style="font-size: 10pt">来编译你的应用程序，以便获得所有新的功能特色，而且几乎不用对应用程序的源代码做任何修改。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">应用程序框架还提供可重用的代码。代码重用是象 </span><span style="font-size: 10pt">C++ </span><span style="font-size: 10pt">这样的面向对象的编程方法得以发展的主要原因之一。通过将可重用的代码封装为类，你可以很容易地使用已经存在的类来添加需要的功能。代码重用使得你可以使用经过严格测试的代码来构造你的应用程序，并很容易获得预期的功能。而且你还可以很容易地将你编写的类与其它需要同样功能的人进行共享。</span></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt">与你自己创建所需框架而言，使用应用程序框架有时会使得你的程序稍大一些。因为现代计算机通常都配置了足够数量的内存，而且这个框架可以作为一个</span><span style="font-size: 10pt"> DLL </span><span style="font-size: 10pt">来使用，所以增加这么一些程序体积还是很值得的。</span><span style="font-size: 10pt">PowerPlant </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> MFC </span><span style="font-size: 10pt">是两个很值得你去熟练使用的高效的工具。</span><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></div>
<div><font size="3"><strong>如何安装和使用</strong><strong> MFC 接口工具</strong></font></div>
<div><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp; MFC </span><span style="font-size: 10pt">接口工具</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">包括对话编辑器和图象编辑器</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">可以在</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">安装光盘上找到。但是，它们并不是作为</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">安装程序的一部分存在的，因此在完成了</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">的安装后，在硬盘上你还是找不到</span><span style="font-size: 10pt"> MFC</span><span style="font-size: 10pt">。为了安装这些工具，请按照以下步骤进行： </span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><span style="font-size: 10pt">找到</span><span style="font-size: 10pt"> iTOOLS.Exe </span><span style="font-size: 10pt">文件。这是安装</span><span style="font-size: 10pt"> MFC </span><span style="font-size: 10pt">接口工具必须的安装程序。</span><span style="font-size: 10pt">iTools.Exe </span><span style="font-size: 10pt">文件可以在</span><span style="font-size: 10pt"> C:\Program Files\Metrowerks\CodeWarrior\BinSDK\bin\ </span><span style="font-size: 10pt">目录下找到。如果在那儿找不到这个文件，那么就到</span><span style="font-size: 10pt"> CodeWarrior </span><span style="font-size: 10pt">的安装光盘上去找。该文件应该在</span><span style="font-size: 10pt"> Extras\SKDs\Win32\Microsoft Win32 SDK Tools\</span><span style="font-size: 10pt">目录下。</span></li>
</ul>
<div style="margin: 0cm 36pt 0pt"><strong><span style="font-size: 10pt">注意</span></strong><strong><span style="font-size: 10pt">:</span></strong><span style="font-size: 10pt">该安装文件</span><span style="font-size: 10pt"> (iTOOLS.Exe) </span><span style="font-size: 10pt">将会询问你想在哪里保存</span><span style="font-size: 10pt"> MFC </span><span style="font-size: 10pt">接口工具。但不行的是，它却没有提供定位目录用的浏览</span><span style="font-size: 10pt">(browser)</span><span style="font-size: 10pt">按钮可用，因此你必须手工的输入一个路径。如果你并不能确定你输入的路径是否就是你想要保存这些工具的路径，你可以先在那个目录中找到一个文件，然后通过查看该文件的属性</span><span style="font-size: 10pt">(</span><span style="font-size: 10pt">在该文件上点击右键然后选择</span><span style="font-size: 10pt"> Properties </span><span style="font-size: 10pt">项</span><span style="font-size: 10pt">)</span><span style="font-size: 10pt">，从这个属性框上你可以复制到完整的路径，并把它填入到安装过程中提示要输入安装路径的编辑框中。</span></div>
<ul style="margin-top: 0cm" type="disc">
    <li><span style="font-size: 10pt">这些工具将要被安装到目的安装路径的</span><span style="font-size: 10pt"> \bin\ </span><span style="font-size: 10pt">目录中。在这个路径中你将可以找到对话框编辑器</span><span style="font-size: 10pt">(DlgEdit.Exe)</span><span style="font-size: 10pt">，图象编辑器</span><span style="font-size: 10pt">(ImagEdit.Exe)</span><span style="font-size: 10pt">和其它一些有用的工具；</span></li>
    <li><span style="font-size: 10pt">如果你正在开发</span><span style="font-size: 10pt"> Windows 95 </span><span style="font-size: 10pt">或</span><span style="font-size: 10pt"> Windows NT</span><span style="font-size: 10pt">，需要的工具可以在</span><span style="font-size: 10pt"> \bin\win95 </span><span style="font-size: 10pt">和</span><span style="font-size: 10pt"> \bin\winnt </span><span style="font-size: 10pt">目录中找到。</span></li>
</ul>
</div>]]></description></item></channel></rss>