您的位置:首页 > 编程语言 > C语言/C++

C语言程序设计 第一章C语言概述.4

2017-09-02 08:33 399 查看
Q&A

Q:  What is this Q&A section anyway?

问:“问与答”究竟是什么

A:  Glad you asked. The Q&A section,which appears at the end of each chapter, serves several purposes.The
primary purpose of Q&A is to tackle questions that are frequently asked by students learning C. Readers can participate in a dialogue (more or less) with the
author, much the same as if they were attending one of my C classes.

答:很高兴有此一问。“问与答”将出现在每章的结尾。设置它主要有以下几个目的。最主要的目的是解决学生学习C语言时经常遇到的问题。读者可以(或多或少)参与和作者的对话,这种形式非常像是读者上了一节作者讲的C语言课。

Another purpose of Q&A is io provide additional information about topics covered in the chapter. Readers of this book will likely
have widely varying backgrounds. Some will be experienced in other programming languages, whereas others
will be learning to program for the first time. Readers with experience in a variety of languages may be satisfied with a brief explanation and a couple of examples.
but readers with less experience may need more. The bottom line: If you find the coverage of a topic to be sketchy, check Q&A for more details.

另一个目的是为对应章中涉及的某些主题提供额外的信息。本书的读者可能会有不同的知识背景。有些读者可能具有其他编程语言的经验,而另外一些读者可能是第一次学习编程。有多种语言经验的读者也许会满足于简要的说明和几个示例,而那些缺少经验的读者则需要更多内容。最基本原则是:如果发现内容不够详细,那么请查阅“问与答”部分获取更多的信息。

On occasion, Q&A will discuss common differences among C compilers. For example, we'll cover some frequently used (but nonstandard)
features that are provided by particular compilers.

必要时,“问与答”中会讨论多种C语言编译器的常见差异。例如,我们将会介绍一些频繁使用(但未标准化)的、DOS编译器和UNIX编译器都支持的特性。

Q:    What does lint do? [p. 6]

问:lint是做什么的?

A:lint checks a C program for a host of potential errors. including-but not limited to-suspicious combinations of types, unused
variables, unreachable code. and nonportable code. It produces a list of diagnostic messages. which the programmer must
then sift through. The advantage of using lint is that it can detect errors that are missed by the compiler. On the other hand. you've got to remember to use lint;
it's all too easy to forget about it. Worse still, lint can produce messages by the hundreds, of which only a fraction refer to actual errors.

答:lint检查C程序中潜在的错误,它会产生一系列诊断信息。然后,程序员需要从头到尾过滤这些信息。使用lint的好处是,它可以检查出被编译器漏掉的错误。另一方面,我们需要记住使用lint,因为它太容易被忘记了。更糟的是,lint可以产生数百条信息,而这些信息中只有少部分涉及了实际错误。

Q:  Where did lint get its name?

A:  Unlike the names of many other UNIX tools, lint isn't an acronym; it got its name from the way it picks up pieces of "fluff"
from a program.

答:与许多其他UNIXI具不同,lint(棉绒)不是缩写。它的命名是因为它像在程序中“吹毛求疵”

Q:  How do I get a copy of lint?

A: lint is a standard UNIX utility; if you rely on another operating system. then you probably don't have lint. Fortunately.
versions of lint are available from third parties. An enhanced version of lint known as splint (Secure Programming Lint)
is included in many Linux distributions and can be downloaded for free from wwvv:splint.org.

答:如果使用UNIX系统,那么将会自动获得lint,因为它是一个标准的UNIX工具。如果采用其他操作系统,则可能没有lint。幸运的是,lint的各种版本可以从第三方那里获得。

Q:  Is there some way to force a compiler to do a more thorough job of error-checking,
without having to use lint?


问:在不使用lint的情况下,有没有其他方式使编译器做更全面的错误检查?

A:Yes. Most compilers will do a more thorough check of a program if asked to. In addition
to checking for errors (undisputed violations of the rules of C), most compilers also produce warning messages, indicating potential trouble spots. Some compilers
have more than one "warning level"; selecting a higher level causes the compiler to check for more problems than choosing a lower level.If your compiler supports
warning levels. it's a good idea to select the highest level. causing the compiler to perform the most thorough job of checking that it's capable of. Errorchecking
options for the GCC compiler. which is distributed with Linux. are discussed in the Q&A section at the end of Chapter 2.

答:有的,许多编译器在有要求的情况下会对程序做全面的检查。除了错误检查外,相当多的编译器也会产生警告信息,提示潜在的问题点。许多编译器有着不止唯一的警告等级,选择更高等级相对于低一些的等级来说,会使编译器检查出更多的问题。如果你的编译器支持警告等级,将其设置为更高等级将是一个好的想法。导致编译器在力所能及的范围内做到更全面的检查。

*Q:   I'm interested in making my program as reliable as possible. Are there any other
tools available besides lint and debuggers?


问:我很关心能让程序尽可能可靠的方法。除了lint和调试工具以外,还有其他有效的工具吗?

A:Yes. Other common tools include "bounds-checkers" and "leak-finders." C doesn't require that array subscripts be checked:
a bounds-checker adds this capability. A leak-finder helps locate "memory leaks": blocks of memory that are dynamically allocated
but never deallocated.

答:有的。其他常用的工具包括越界检查工具(bounds-checker)和内存泄漏监测工具(leak-finder)。C语言不要求检查数组下标,而越界检查工具增加了此项功能。内存泄漏监测工具帮助定位“内存泄漏”,即那些动态分配却从未被释放的内存块。

上一章C语言程序设计
第一章C语言概述.3

tackle vt. 解决; 应付

acronym 缩写字
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: