📄 questions.html
字号:
(i.e. not <TT>sizeof(char)</TT>).</p><p><a href="charstring/wchar.html" rel=subdocument>8.10</a>I'm starting to think about multinational character sets,and I'm worried about the implicationsof making <TT>sizeof(char)</TT> be 2so that 16-bit character sets can be represented.</p><hr><H4>9. Boolean Expressions and Variables</H4><p><a href="bool/booltype.html" rel=subdocument>9.1</a>What is the right type to use for Boolean values in C?Is there a standard type?ShouldI use<TT>#define</TT>s or enumsfor the true and false values?</p><p><a href="bool/bool2.html" rel=subdocument>9.2</a>Isn't #defining <TT>TRUE</TT> to be 1 dangerous, since any nonzero valueis considered ``true'' in C?What if a built-in logical or relational operator ``returns''something other than 1?</p><p><a href="bool/ifptr.html" rel=subdocument>9.3</a>Is <TT>if(p)</TT>,where <TT>p</TT> is a pointer,avalidand portable test?</p><p><a href="bool/macros.html" rel=subdocument>9.4</a>Should I use symbolic names like <TT>TRUE</TT>and <TT>FALSE</TT> for Boolean constants,or plain 1 and 0?</p><p><a href="bool/thirdparty.html" rel=subdocument>9.5</a>Athird-partyheader fileI just started usingis defining its own <TT>TRUE</TT>and <TT>FALSE</TT> valuesincompatibly withthe code I've already developed.What can I do?</p><hr><H4>10. C Preprocessor</H4><p><a href="cpp/safemacros.html" rel=subdocument>10.1</a>I'm trying to definea few simple little function-like macrossuch as<pre> #define square(x) x * x</pre>but they're not always working.</p><p><a href="cpp/slm.html" rel=subdocument>10.2</a>Here aresome cute preprocessor macros:<pre> #define begin { #define end }</pre>With these,I can write C code that looks more like Pascal.What do y'all think?</p><p><a href="cpp/swapmacro.html" rel=subdocument>10.3</a>How can I write a generic macro to swap two values?</p><p><a href="cpp/multistmt.html" rel=subdocument>10.4</a>What's the best way to write a multi-statement macro?</p><p><a href="cpp/typedefvsdefine.html" rel=subdocument>10.5</a>What's the difference between using a <TT>typedef</TT>ora <TT>#define</TT>for a user-defined type?</p><p><a href="cpp/constvsdefine.html" rel=subdocument>10.5b</a>What's the difference between<pre> const MAXSIZE = 100;</pre><pre>and</pre><pre> #define MAXSIZE 100</pre></p><p><a href="cpp/hfiles.html" rel=subdocument>10.6</a>I'm splitting up a programinto multiple source filesfor the first time,and I'm wondering what to put in <TT>.c</TT> filesand what to put in <TT>.h</TT> files.(What does ``<TT>.h</TT>''mean,anyway?)</p><p><a href="cpp/nestincl.html" rel=subdocument>10.7</a>Is it acceptable for one header file to <TT>#include</TT> another?</p><p><a href="cpp/inclkinds.html" rel=subdocument>10.8a</a>What's the difference between<TT>#include <></TT>and<TT>#include ""</TT>?</p><p><a href="cpp/cppsearchpath.html" rel=subdocument>10.8b</a>What are the complete rules for header file searching?</p><p><a href="cpp/headerglom.html" rel=subdocument>10.9</a>I'm getting strangesyntax errorson the very firstdeclaration ina file,but it looks fine.</p><p><a href="cpp/def3rdparty.html" rel=subdocument>10.10</a>I'm using header fileswhichaccompany two different third-party libraries,and they are ``helpfully'' definingcommon macros such as <TT>TRUE</TT>,<TT>FALSE</TT>,<TT>Min()</TT>,and <TT>Max()</TT>,but the definitions clash with each otherand with definitions I'dalready established in my own header files.What can I do?</p><p><a href="cpp/extlibs.html" rel=subdocument>10.10b</a>I'm #including therightheader file forthe library function I'm using,but the linker keeps saying it's undefined.</p><p><a href="cpp/missinghdr.html" rel=subdocument>10.11</a>I'm compiling a program, andI seem to be missingoneof theheader files itrequires.Can someone send mea copy?</p><p><a href="cpp/ifstrcmp.html" rel=subdocument>10.12</a>How can I construct preprocessor <TT>#if</TT> expressionswhich compare strings?</p><p><a href="cpp/ifexpr.html" rel=subdocument>10.13</a>Does the <TT>sizeof</TT> operator work in preprocessor <TT>#if</TT> directives?</p><p><a href="cpp/ifddef.html" rel=subdocument>10.14</a>Can I use an <TT>#ifdef</TT> in a <TT>#define</TT> line,to define something two differentways,like this?<pre> #define a b \ #ifdef whatever c d #else e f g #endif</pre></p><p><a href="cpp/iftypedef.html" rel=subdocument>10.15</a>Is there anything likean <TT>#ifdef</TT> for <TT>typedef</TT>s?</p><p><a href="cpp/ifendian.html" rel=subdocument>10.16</a>How can I use a preprocessor <TT>#if</TT> expression totellwhether a machine's byte orderis big-endian or little-endian?</p><p><a href="cpp/ifdefsyntax.html" rel=subdocument>10.17</a>I'm getting strange syntax errors insidelinesI've<TT>#ifdef</TT>fed out.</p><p><a href="cpp/unifdef.html" rel=subdocument>10.18</a>I inherited some codewhich contains far too many <TT>#ifdef</TT>'s for my taste.How can I preprocessthecodetoleave only one conditional compilation set,without running it through the preprocessorand expanding all of the <TT>#include</TT>'s and <TT>#define</TT>'s as well?</p><p><a href="cpp/listpredef.html" rel=subdocument>10.19</a>How can I list all of the predefined identifiers?</p><p><a href="cpp/oldpaste.html" rel=subdocument>10.20</a>I have some old code that tries to construct identifiers with amacro like<pre>#define Paste(a, b) a/**/b</pre>but it doesn't work any more.</p><p><a href="cpp/charize.html" rel=subdocument>10.21</a>I have an old macro<pre>#define CTRL(c) ('c' & 037)</pre>that doesn'tseem towork any more.</p><p><a href="cpp/macstrexp2.html" rel=subdocument>10.22</a>Why is the macro<pre> #define TRACE(n) printf("TRACE: %d\n", n)</pre>giving me the warning ``macro replacement within a string literal''?It seems to be expanding<pre> TRACE(count);</pre>as<pre> printf("TRACE: %d\count", count);</pre></p><p><a href="cpp/macstrexp1.html" rel=subdocument>10.23</a>How can Iusea macro argumentinsidea stringliteralin the macro expansion?</p><p><a href="cpp/stringize.html" rel=subdocument>10.24</a>I'm trying to usethe ANSI ``stringizing'' preprocessing operator`<TT>#</TT>'to insert the value of a symbolic constant into a message,but it keepsstringizing the macro's name rather than itsvalue.</p><p><a href="cpp/notgeneral.html" rel=subdocument>10.25</a>I've got this tricky preprocessing I want to doandI can't figure out a wayto do it.</p><p><a href="cpp/varargs.html" rel=subdocument>10.26</a>How can I write a macro which takes a variable number ofarguments,or use the preprocessor to ``turn off'' a function call with avariable number of arguments?</p><p><a href="cpp/debugmacs.html" rel=subdocument>10.27</a>How can I include expansions of the <TT>__FILE__</TT>and <TT>__LINE__</TT> macrosin a general-purpose debugging macro?</p><hr><H4>11. ANSI/ISO Standard C</H4><p><a href="ansi/ansi1.html" rel=subdocument>11.1</a>What is the ``ANSI C Standard?''</p><p><a href="ansi/avail.html" rel=subdocument>11.2</a>How can I get a copy of the Standard?</p><p><a href="ansi/updates.html" rel=subdocument>11.2b</a>Where can I get information about updates to the Standard?</p><p><a href="ansi/argpromos.html" rel=subdocument>11.3</a>My ANSI compilercomplains about a mismatch when it sees<pre> extern int func(float); int func(x) float x; { ...</pre></p><p><a href="ansi/mixoldandnew.html" rel=subdocument>11.4</a>Can you mix old-style and new-stylefunction syntax?</p><p><a href="ansi/structinproto.html" rel=subdocument>11.5</a>Why does the declaration<pre>extern int f(struct x *p);</pre>give mean obscurewarning messageabout``struct x declared inside parameter list''?</p><p><a href="ansi/varargproto.html" rel=subdocument>11.6</a>I had a frustrating problem which turned out to be caused by the line<pre> printf("%d", n);</pre>where <TT>n</TT> was actually a <TT>long int</TT>.I thought that ANSI function prototypeswere supposed to guard against argument type mismatches like this.</p><p><a href="ansi/varargproto2.html" rel=subdocument>11.7</a>I heard that you have to <TT>#include</TT> <TT><stdio.h></TT>before calling <TT>printf</TT>.Why?</p><p><a href="ansi/constasconst.html" rel=subdocument>11.8</a>I don't understand why I can'tuse <TT>const</TT> values in initializers and arraydimensions,as in<pre> const int n = 5; int a[n];</pre></p><p><a href="ansi/strlitnotconst.html" rel=subdocument>11.8b</a>If you can't modify string literals,why aren't they defined as beingarrays of <TT>const</TT> characters?</p><p><a href="ansi/constptrconst.html" rel=subdocument>11.9</a>What's the difference between<TT>const char *p</TT>,<TT>char const *p</TT>,and <TT>char * const p</TT>?</p><p><a href="ansi/constmismatch.html" rel=subdocument>11.10</a>Why can't I pass a <TT>char **</TT> to a function which expects a<TT>const char **</TT>?</p><p><a href="ansi/typedefconst.html" rel=subdocument>11.11</a>I've gotthe declarations<pre> typedef char *charp; const charp p;</pre>Why is <TT>p</TT> turning out <TT>const</TT>,instead of the characters pointed to?</p><p><a href="ansi/constvsdefine2.html" rel=subdocument>11.11b</a>What's the difference between<pre> const MAXSIZE = 100;</pre><pre>and</pre><pre> #define MAXSIZE 100</pre></p><p><a href="ansi/maindecl.html" rel=subdocument>11.12a</a>What's the correct declaration of <TT>main()</TT>?</p><p><a href="ansi/voidmain.html" rel=subdocument>11.12b</a>Can I declare <TT>main</TT> as <TT>void</TT>,to shut off these annoying``main returns no value'' messages?</p><p><a href="ansi/envp.html" rel=subdocument>11.13</a>But what about <TT>main</TT>'s third argument,<TT>envp</TT>?</p><p><a href="ansi/voidmain3.html" rel=subdocument>11.14a</a>I believe that declaring <TT>void main()</TT> can't fail,since I'm calling <TT>exit</TT> instead of returning,and anyway my operating system ignores a program's exit/return status.</p><p><a href="ansi/voidmainexamp.html" rel=subdocument>11.14b</a>So what could go wrong?Are therereally anysystems where <TT>void main()</TT> doesn't work?</p><p><a href="ansi/voidmainbooks.html" rel=subdocument>11.15</a>The book I've been using,<I>C Programingfor the Compleat Idiot</I>,always uses <TT>void main()</TT>.</p><p><a href="ansi/exitvsreturn.html" rel=subdocument>11.16</a>Is <TT>exit(status)</TT> truly equivalentto returning the same <TT>status</TT> from <TT>main</TT>?</p><p><a href="ansi/stringize.html" rel=subdocument>11.17</a>I'm trying to usethe ANSI ``stringizing'' preprocessing operator`<TT>#</TT>'to insert the value of a symbolic constant into a message,but it keepsstringizing the macro's name rather than itsvalue.</p><p><a href="ansi/macstrexp.html" rel=subdocument>11.18</a>What does the message``warning: macro replacement within a string literal''mean?</p><p><a href="ansi/ifdefsyntax.html" rel=subdocument>11.19</a>I'm getting strange syntax errors insidelinesI've<TT>#ifdef</TT>fed out.</p><p><a href="ansi/pragma.html" rel=subdocument>11.20</a>What are <TT>#pragma</TT>s and what are they good for?</p><p><a href="ansi/pragmaonce.html" rel=subdocument>11.21</a>What does ``<TT>#pragma once</TT>'' mean?I found it in some header files.</p><p><a href="ansi/nonstrings.html" rel=subdocument>11.22</a>Is <TT>char a[3] = "abc";</TT> legal?What does it mean?</p><p><a href="ansi/aryvsadr.html" rel=subdocument>11.23</a>Since array references decay into pointers,if <TT>arr</TT> is an array,what'sthe difference between<TT>arr</TT> and <TT>&arr</TT>?</p><p><a href="ansi/voidparith.html" rel=subdocument>11.24</a>Why can't I perform arithmetic on a <TT>void *</TT> pointer?</p><p><a href="ansi/memmove.html" rel=subdocument>11.25</a>What's the difference between<TT>memcpy</TT> and<TT>memmove</TT>?</p><p><a href="ansi/malloc0.html" rel=subdocument>11.26</a>What should <TT>malloc(0)</TT> do?Return a null pointer or a pointer to 0 bytes?</p><p><a href="ansi/extidsignif.html" rel=subdocument>11.27</a>Why does the ANSI Standardplace limits onthe lengthand case-significanceofexternal identifiers?</p><p><a href="ansi/noalias.html" rel=subdocument>11.28</a>What was <TT>noalias</TT> and what ever happened to it?</p><p><a href="ansi/preansi.html" rel=subdocument>11.29a</a>My compiler is rejecting the simplest possible test programs,with all kinds of syntax errors.It's complaining about thefirst line of<pre> main(int argc, char **argv) { return 0; }</pre></p><p><a href="ansi/preansi2.html" rel=subdocument>11.29b</a>What does the message``Automatic aggregate intialization is an ANSI feature''mean?My compiler is complaining about valid ANSI code.</p><p><a href="ansi/preansilib.html" rel=subdocument>11.30</a>Why are some ANSI/ISO Standard library functions showing up asundefined, even though I've got an ANSI compiler?</p><p><a href="ansi/cproto.html" rel=subdocument>11.31</a>Does anyone have a tool for converting old-style C programs toANSI C,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -