⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questions.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</p><p><a href="struct/initunion.html" rel=subdocument>2.20</a>Can I initialize unions?</p><p><a href="struct/taggedunion.html" rel=subdocument>2.21</a>Is there an automatic wayto keep track of which field of a union is in use?</p><p><a href="struct/enumvsdefine.html" rel=subdocument>2.22</a>What's the difference betweenan enumeration and a set ofpreprocessor <TT>#define</TT>s?</p><p><a href="struct/enumport.html" rel=subdocument>2.23</a>Are enumerations really portable?<br>Aren't they Pascalish?<br></p><p><a href="struct/enumprint.html" rel=subdocument>2.24</a>Is there an easy way to print enumeration values symbolically?</p><p><a href="struct/bitfield0.html" rel=subdocument>2.25</a>I came across some structure declarations with colons and numbers next to certainfields,like this:<pre>struct record {	char *name;	int refcount : 4;	unsigned dirty : 1;};</pre>What gives?</p><p><a href="struct/bitfields.html" rel=subdocument>2.26</a>Why do people use explicit masks andbit-twiddlingcode so much,instead of declaring bit-fields?</p><hr><H4>3. Expressions</H4><p><a href="expr/evalorder1.html" rel=subdocument>3.1</a>Why doesn'tthis code:<pre>a[i] = i++;</pre>work?</p><p><a href="expr/evalorder2.html" rel=subdocument>3.2</a>Under my compiler, the code<pre>int i&nbsp;=&nbsp;7;printf("%d\n",&nbsp;i++&nbsp;*&nbsp;i++);</pre>prints 49.Regardless of the order of evaluation, shouldn't it print 56?</p><p><a href="expr/ieqiplusplus.html" rel=subdocument>3.3</a>I've experimented withthe code<pre>int i&nbsp;=&nbsp;3;i&nbsp;=&nbsp;i++;</pre>on several compilers.Some gave <TT>i</TT> thevalue 3,andsome gave 4.Which compiler is correct?</p><p><a href="expr/xorswapexpr.html" rel=subdocument>3.3b</a>Here's a slick expression:<pre>a&nbsp;^=&nbsp;b&nbsp;^=&nbsp;a&nbsp;^=&nbsp;b</pre>It swaps <TT>a</TT> and <TT>b</TT> without using a temporary.</p><p><a href="expr/precvsooe.html" rel=subdocument>3.4</a>Can I use explicit parentheses to forcethe order of evaluation I want,and control these side effects?Even if I don't, doesn't precedence dictate it?</p><p><a href="expr/seqpointops.html" rel=subdocument>3.5</a>But what about the<TT>&amp;&amp;</TT>and<TT>||</TT>operators?<br>I see code like ``<TT>while((c&nbsp;=&nbsp;getchar())&nbsp;!=&nbsp;EOF&nbsp;&amp;&amp;&nbsp;c&nbsp;!=&nbsp;'\n')</TT>'' ...</p><p><a href="expr/shortcircuit.html" rel=subdocument>3.6</a>Is it safe to assumethat the right-hand sideof the<TT>&amp;&amp;</TT>and<TT>||</TT>operatorswon't be evaluatedif the left-hand side determines the outcome?</p><p><a href="expr/comma.html" rel=subdocument>3.7</a>Why did<pre>printf("%d&nbsp;%d",&nbsp;f1(),&nbsp;f2());</pre>call <TT>f2</TT> first?I thought the comma operator guaranteed left-to-right evaluation.</p><p><a href="expr/seqpoints.html" rel=subdocument>3.8</a>How can I understandcomplex expressions like the ones in this section,and avoid writing undefined ones?What's a ``sequence point''?</p><p><a href="expr/evalorder4.html" rel=subdocument>3.9</a>Soif I write<pre>a[i]&nbsp;=&nbsp;i++;</pre>and I don't carewhich cell of <TT>a[]</TT> gets written to,the code is fine,and <TT>i</TT> getsincremented by one,right?</p><p><a href="expr/experiment.html" rel=subdocument>3.10a</a>People keep saying that the behaviorof <TT>i&nbsp;=&nbsp;i++</TT>is undefined,butI just triediton an ANSI-conforming compiler,and got the results I expected.</p><p><a href="expr/expec0.html" rel=subdocument>3.10b</a>People told me that if I evaluated an undefined expression,or accessed an uninitialized variable,I'd get a random, garbage value.But I tried it, and got <em>zero</em>.What's up with that?</p><p><a href="expr/confused.html" rel=subdocument>3.11</a>How can I avoid these undefined evaluation order difficultiesif I don't feel like learning the complicated rules?</p><p><a href="expr/prevspost.html" rel=subdocument>3.12a</a>What's the difference between <TT>++i</TT> and <TT>i++</TT>?</p><p><a href="expr/plusplus.html" rel=subdocument>3.12b</a>If I'm not using the value of the expression,should I use <TT>++i</TT> or <TT>i++</TT> to increment a variable?</p><p><a href="expr/transitivity.html" rel=subdocument>3.13</a>I need to check whether one number lies between two others.Why doesn't<pre>if(a &lt; b &lt; c)</pre>work?</p><p><a href="expr/intoverflow1.html" rel=subdocument>3.14</a>Why doesn't the code<pre>int&nbsp;a&nbsp;=&nbsp;1000,&nbsp;b&nbsp;=&nbsp;1000;long&nbsp;int&nbsp;c&nbsp;=&nbsp;a&nbsp;*&nbsp;b;</pre>work?</p><p><a href="expr/intovf3.html" rel=subdocument>3.14b</a>How can I ensure that integer arithmetic doesn't overflow?</p><p><a href="expr/truncation1.html" rel=subdocument>3.15</a>Why does the code<pre>double degC, degF;degC = 5 / 9 * (degF - 32);</pre>keep giving me 0?</p><p><a href="expr/qcolonlhs.html" rel=subdocument>3.16</a>I have a complicated expression whichI haveto assignto one of two variables,depending on a condition.Can I use code like this?<pre>	((condition) ? a : b) = complicated_expression;</pre></p><p><a href="expr/ternprec.html" rel=subdocument>3.17</a>I havesome codecontaining expressionslike<pre>a ? b = c : d</pre>and some compilers are accepting it but some are not.</p><p><a href="expr/unswarn.html" rel=subdocument>3.18</a>What does the warning``semantics of `<TT>&gt;</TT>' change in ANSI C''mean?</p><p><a href="expr/preservingrules.html" rel=subdocument>3.19</a>What's the difference between the ``unsigned preserving''and ``value preserving'' rules?</p><hr><H4>4. Pointers</H4><p><a href="ptrs/goodfor.html" rel=subdocument>4.1</a>What are pointers really good for, anyway?</p><p><a href="ptrs/mimic.html" rel=subdocument>4.2</a>I'm trying to declare a pointer and allocate some space for it,but it'snot working.What's wrong withthis code?<pre>char *p;*p = malloc(10);</pre></p><p><a href="ptrs/unopprec2.html" rel=subdocument>4.3</a>Does <TT>*p++</TT> increment <TT>p</TT>,or what it points to?</p><p><a href="ptrs/explscale.html" rel=subdocument>4.4</a>I'mtrying to usepointers tomanipulate an array of <TT>int</TT>s.What's wrong with this code?<pre>	int array[5], i, *ip;	for(i = 0; i &lt; 5; i++) array[i] = i;	ip = array;	printf("%d\n", *(ip + 3 * sizeof(int)));</pre>I expected the last line to print 3,but it printed garbage.</p><p><a href="ptrs/castincr.html" rel=subdocument>4.5</a>Ihavea <TT>char&nbsp;*</TT> pointerthat happens to point tosome <TT>int</TT>s,and I want to step it over them.Why doesn't<pre>((int *)p)++;</pre>work?</p><p><a href="ptrs/voidparith.html" rel=subdocument>4.6</a>Why can't I perform arithmetic on a <TT>void&nbsp;*</TT> pointer?</p><p><a href="ptrs/align.html" rel=subdocument>4.7</a>I've got some code that's trying to unpack external structures, but it's crashingwith a message about an ``unaligned access.''What does this mean?</p><p><a href="ptrs/passptrinit.html" rel=subdocument>4.8</a>I have a function which accepts,and is supposed to initialize,a pointer:<pre>	void f(int *ip)	{		static int dummy = 5;		ip = &amp;dummy;	}</pre>But when I call it like this:<pre>	int *ip;	f(ip);</pre>thepointer in the caller remains unchanged.</p><p><a href="ptrs/genericpp.html" rel=subdocument>4.9</a>Suppose I want to write a function that takes a generic pointeras an argument and I want to simulate passing it by reference.Can I give the formal parameter type <TT>void&nbsp;**</TT>,and do something like this?<pre>	void f(void **);	double *dp;	f((void **)&amp;dp);</pre></p><p><a href="ptrs/refconst.html" rel=subdocument>4.10</a>I have a function<pre>	extern int f(int *);</pre>which accepts a pointer to an <TT>int</TT>.How can I pass a constantby reference?A call like<pre>	f(&amp;5);</pre>doesn't seem to work.</p><p><a href="ptrs/passbyref.html" rel=subdocument>4.11</a>Does C even have ``pass by reference''?</p><p><a href="ptrs/funccall.html" rel=subdocument>4.12</a>I've seen different syntax used for calling functions via pointers.What's the story?</p><p><a href="ptrs/generic.html" rel=subdocument>4.13</a>What's the total generic pointer type?My compiler complainedwhen I tried to stuff function pointers into a <TT>void&nbsp;*</TT>.</p><p><a href="ptrs/int2ptr.html" rel=subdocument>4.14</a>How are integers converted to and from pointers?Can I temporarily stuff an integer into a pointer,or vice versa?</p><p><a href="ptrs/int2charp.html" rel=subdocument>4.15</a>How do I convert an <TT>int</TT> to a <TT>char&nbsp;*</TT>?I tried a cast, but it's not working.</p><p><a href="ptrs/charstarws3.html" rel=subdocument>4.16</a>What's wrong withthisdeclaration?<pre>char* p1, p2;</pre>I get errors when I try touse<TT>p2</TT>.</p><p><a href="ptrs/nearfar2.html" rel=subdocument>4.17</a>What are ``near'' and ``far'' pointers?</p><hr><H4>5. Null Pointers</H4><p><a href="null/null1.html" rel=subdocument>5.1</a>What is this infamous null pointer, anyway?</p><p><a href="null/null2.html" rel=subdocument>5.2</a>How do I get a null pointer in my programs?</p><p><a href="null/ptrtest.html" rel=subdocument>5.3</a>Is the abbreviated pointer comparison ``<TT>if(p)</TT>'' to test fornon-null pointers valid?What if the internal representation for null pointers is nonzero?</p><p><a href="null/macro.html" rel=subdocument>5.4</a>What is <TT>NULL</TT> and how is itdefined?</p><p><a href="null/machnon0.html" rel=subdocument>5.5</a>How should <TT>NULL</TT> be defined on a machine which uses a nonzero bitpattern as the internal representation of a null pointer?</p><p><a href="null/safermacs.html" rel=subdocument>5.6</a>If <TT>NULL</TT> were defined asfollows:<pre>	#define NULL ((char *)0)</pre>wouldn't that make function calls which pass an uncast <TT>NULL</TT> work?</p><p><a href="null/long0.html" rel=subdocument>5.7</a>My vendor provides header files that <TT>#define</TT> <TT>NULL</TT> as <TT>0L</TT>.Why?</p><p><a href="null/fcnptr.html" rel=subdocument>5.8</a>Is <TT>NULL</TT> valid for pointers to functions?</p><p><a href="null/nullor0.html" rel=subdocument>5.9</a>If <TT>NULL</TT> and <TT>0</TT> are equivalentas null pointer constants,which should I use?</p><p><a href="null/macsochange.html" rel=subdocument>5.10</a>But wouldn't it be better to use <TT>NULL</TT>(rather than<TT>0</TT>),in case the value of <TT>NULL</TT> changes,perhaps on a machine with nonzero internal null pointers?</p><p><a href="null/nullreq.html" rel=subdocument>5.11</a>I once used a compiler that wouldn't work unless <TT>NULL</TT> wasused.</p><p><a href="null/nullptrmacro.html" rel=subdocument>5.12</a>I use the preprocessor macro<pre>#define Nullptr(type) (type *)0</pre>to help me build null pointers of the correct type.</p><p><a href="null/varieties.html" rel=subdocument>5.13</a>This is strange.<TT>NULL</TT> is guaranteed to be <TT>0</TT>, but the null pointer is not?</p><p><a href="null/confusion.html" rel=subdocument>5.14</a>Why is there so much confusion surrounding null pointers?Why do these questions come up so often?</p><p><a href="null/confused2.html" rel=subdocument>5.15</a>I'm confused.I just can't understand all this null pointer stuff.</p><p><a href="null/confusion4.html" rel=subdocument>5.16</a>Given all the confusion surrounding null pointers,wouldn't it be easier simplyto require them to be representedinternally by zeroes?</p><p><a href="null/machexamp.html" rel=subdocument>5.17</a>Seriously, have any actual machines really used nonzero nullpointers,or different representations for pointers to different types?</p><p><a href="null/runtime0.html" rel=subdocument>5.18</a>Is a run-time integral value of 0,cast to a pointer,guaranteed to be a null pointer?</p><p><a href="null/accessloc0.html" rel=subdocument>5.19</a>How can I accessan interrupt vectorlocated atthe machine's location 0?If I set a pointer to <TT>0</TT>,the compiler might translate it to some nonzero internal nullpointer value.</p><p><a href="null/nullpassign.html" rel=subdocument>5.20</a>What does a run-time ``null pointer assignment'' error mean?How can I track it down?</p><hr><H4>6. Arrays and Pointers</H4><p><a href="aryptr/aryptr1.html" rel=subdocument>6.1</a>I had the definition <TT>char&nbsp;a[6]</TT> in one source file, and inanother I declared <TT>extern&nbsp;char&nbsp;*a</TT>.Why didn't it work?</p><p><a href="aryptr/aryptr2.html" rel=subdocument>6.2</a>But I heard that <TT>char a[]</TT> was identical to <TT>char&nbsp;*a</TT>.</p><p><a href="aryptr/aryptrequiv.html" rel=subdocument>6.3</a>So what is meant by the ``equivalence of pointers and arrays'' in C?</p><p><a href="aryptr/aryptrparam.html" rel=subdocument>6.4</a>If they're so different,thenwhyare array and pointer declarations interchangeable asfunction formal parameters?</p><p><a href="aryptr/arypbref.html" rel=subdocument>6.4b</a>So arrays are passed by reference,even though the rest of C uses pass by value?</p><p><a href="aryptr/arrayassign.html" rel=subdocument>6.5</a>Why can'tIdo something like this?<pre>	extern char *getpass();	char str[10];	str = getpass("Enter password: ");</pre></p><p><a href="aryptr/aryparmasgn.html" rel=subdocument>6.6</a>If you can't assign to arrays,then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -