📄 funnybugs.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:46 2005 by faqproc version 2.7 --><!-- from source file strangeprob.sgml dated Tue Jun 29 21:44:40 2004 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/strangeprob/funnybugs.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:01 GMT --><head><meta name=GENERATOR content="faqproc"><title>Question 16.5</title><link href="crashatexit.html" rev=precedes><link href="strlitnomod.html" rel=precedes><link href="index.html" rev=subdocument></head><body bgcolor="#ffffff"><a href="crashatexit.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="strlitnomod.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a> <a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><p><!-- qbegin --><h1>comp.lang.c FAQ list<font color=blue>·</font><!-- qtag -->Question 16.5</h1><p><font face=Helvetica size=8 color=blue><b>Q:</b></font>This program runs perfectly onone machine,but I get weird results onanother.Stranger still,adding orremoving a debugging printoutchanges the symptoms...</p><p><hr><p><font face=Helvetica size=8 color=blue><b>A:</b></font>Lots of things could be going wrong;here are a few of the more common things to check:<UL><li>uninitialized local variables<a href="stktrash.html" rel=subdocument>[footnote]</a>(see also question <a href="../malloc/malloc1.html">7.1</a>)<li>integer overflow,especially on 16-bit machines,especially of an intermediate result when doingthings like <TT>a * b / c</TT>(see also question <a href="../expr/intoverflow1.html">3.14</a>)<li>undefined evaluation order(see questions <a href="../expr/evalorder1.html">3.1</a> through<a href="../expr/precvsooe.html">3.4</a>)<li>omitteddeclarationof external functions,especially those whichreturnsomethingother than <TT>int</TT>,or have ``narrow'' or variable arguments(see questions<a href="../decl/implfdecl.html">1.25</a>,<a href="../ansi/argpromos.html">11.3</a>,<a href="../fp/fpdecl.html">14.2</a>,and <a href="../varargs/protos.html">15.1</a>)<li>dereferencednull pointers(see section <a href="../null/index.html">5</a>)<li>improper <TT>malloc</TT>/<TT>free</TT> use:assuming <TT>malloc</TT>'ed memory contains 0,assuming <TT>free</TT>d storage persists,<TT>free</TT>ing something twice,corrupting the <TT>malloc</TT> arena(see also questions<a href="../malloc/crash.html">7.19</a>and<a href="../malloc/useafterfree.html">7.20</a>)<li>pointer problems in general(see alsoquestions <a href="ptralign.html">16.7</a> and <a href="segv.html">16.8</a>)<li>mismatch between<TT>printf</TT> formatand arguments,especially trying to print <TT>long int</TT>s using <TT>%d</TT>(seequestions <a href="../stdio/printftypes.html">12.7</a> and <a href="../stdio/scanfvsprintf.html">12.9</a>)<li>trying toallocatemore memory than an <TT>unsigned int</TT> can count,especially on machines with limited memory(see also questions <a href="../malloc/sizewrap.html">7.16</a>and <a href="../osdep/bigdatastr.html">19.23</a>)<li>array bounds problems,especially of small, temporarybuffers,perhaps used for constructing strings with <TT>sprintf</TT><a href="gonzo.html" rel=subdocument>[footnote]</a>(see alsoquestions <a href="../malloc/malloc1.html">7.1</a>, <a href="../stdio/sprintfsize.html">12.21</a>, and <a href="../osdep/system2.html">19.28</a>)<li>invalid assumptions about the mapping of <TT>typedef</TT>s,especially <TT>size_t</TT>(see question <a href="../malloc/sizetlong.html">7.15</a>)<li>floating point problems(see questions <a href="../fp/printfprec.html">14.1</a> and <a href="../fp/strangefp.html">14.4a</a>)<li>anything you thought was a clever exploitationof theway you believe code is generated for yourspecificsystem</UL></p><p>Proper use offunction prototypescan catch several of these problems;<TT>lint</TT> would catch several more.See also questions <a href="biglocal.html">16.3</a>,<a href="crashatexit.html">16.4</a>,and<a href="../resources/lint1.html">18.4</a>.</p><!-- aend --><p><hr><a href="crashatexit.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="strlitnomod.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a> <a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><!-- lastfooter --><a href="../about.html">about this FAQ list</a> <a href="../eskimo.html">about eskimo</a> <a href="../search.html">search</a> <a href="../feedback.html">feedback</a> <a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></body><!-- Mirrored from c-faq.com/strangeprob/funnybugs.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:01 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -