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

📄 appb.html

📁 Kernighan and Ritchie - The C Programming Language c程序设计语言(第二版)称作是C语言学习的圣经
💻 HTML
📖 第 1 页 / 共 4 页
字号:
of function arguments of unknown number and type.<p>Suppose <tt>lastarg</tt> is the last named parameter of a function <tt>f</tt>with a variable number of arguments. Then declare within <tt>f</tt> a variableof type <tt>va_list</tt> that will point to each argument in turn:<pre>   va_list ap;</pre><tt>ap</tt> must be initialized once with the macro <tt>va_start</tt> beforeany unnamed argument is accessed:<p>&nbsp;&nbsp;<tt>va_start(va_list ap, </tt><em>lastarg</em><tt>);</tt><p>Thereafter, each execution of the macro <tt>va_arg</tt> will produce a valuethat has the type and value of the next unnamed argument, and will alsomodify <tt>ap</tt> so the next use of <tt>va_arg</tt> returns the next argument:<p>&nbsp;&nbsp;<em>type</em> <tt>va_arg(va_list ap, </tt><em>type</em><tt>);</tt><p>The macro<pre>   void va_end(va_list ap);</pre>must be called once after the arguments have been processed but before<tt>f</tt> is exited.<h2><a name="sb.8">B.8 Non-local Jumps: &lt;setjmp.h&gt;</a></h2>The declarations in <tt>&lt;setjmp.h&gt;</tt> provide a way to avoid the normalfunction call and return sequence, typically to permit an immediate returnfrom a deeply nested function call.<dl><dt><tt>int setjmp(jmp_buf env)</tt><dd>The macro <tt>setjmp</tt> saves state information in <tt>env</tt> for use by    <tt>longjmp</tt>. The return is zero from a direct call of <tt>setjmp</tt>, and    non-zero from a subsequent call of <tt>longjmp</tt>. A call to <tt>setjmp</tt>    can only occur in certain contexts, basically the test of <tt>if</tt>,    <tt>switch</tt>, and loops, and only in simple relational expressions.</dl><pre>      if (setjmp(env) == 0)          /* get here on direct call */      else          /* get here by calling longjmp */</pre><dl><dt><tt>void longjmp(jmp_buf env, int val)</tt><dd><tt>longjmp</tt> restores the state saved by the most recent call to    <tt>setjmp</tt>, using the information saved in <tt>env</tt>, and execution    resumes as if the <tt>setjmp</tt> function had just executed and returned    the non-zero value <tt>val</tt>. The function containing the <tt>setjmp</tt>    must not have terminated. Accessible objects have the values they had at    the time <tt>longjmp</tt> was called, except that non-<tt>volatile</tt>    automatic variables in the function calling <tt>setjmp</tt> become    undefined if they were changed after the <tt>setjmp</tt> call.</dl><h2><a name="sb.9">B.9 Signals: &lt;signal.h&gt;</a></h2>The header <tt>&lt;signal.h&gt;</tt> provides facilities for handling exceptionalconditions that arise during execution, such as an interrupt signal from anexternal source or an error in execution.<pre>void (*signal(int sig, void (*handler)(int)))(int)</pre><tt>signal</tt> determines how subsequent signals will be handled. If <tt>handler</tt> is <tt>SIG_DFL</tt>, the implementation-defined default behavior isused, if it is <tt>SIG_IGN</tt>, the signal is ignored; otherwise, the functionpointed to by <tt>handler</tt> will be called, with the argument of the type ofsignal. Valid signals include<p><table align="center" border=0><td><tt>SIGABRT</tt></td><td>abnormal termination, e.g., from <tt>abort</tt></td><tr><td><tt>SIGFPE </tt></td><td>arithmetic error, e.g., zero divide or overflow</td><tr><td><tt>SIGILL </tt></td><td>illegal function image, e.g., illegal instruction</td><tr><td><tt>SIGINT </tt></td><td>interactive attention, e.g., interrupt</td><tr><td><tt>SIGSEGV</tt></td><td>illegal storage access, e.g., access outside memory limits</td><tr><td><tt>SIGTERM&nbsp;&nbsp;</tt></td><td>termination request sent to this program</td><tr></table><p><tt>signal</tt> returns the previous value of <tt>handler</tt> for the specificsignal, or <tt>SIG_ERR</tt> if an error occurs.<p>When a signal <tt>sig</tt> subsequently occurs, the signal is restored to itsdefault behavior; then the signal-handler function is called, as if by<tt>(*handler)(sig)</tt>. If the handler returns, execution will resume where itwas when the signal occurred.<p>The initial state of signals is implementation-defined.<pre>int raise(int sig)</pre><tt>raise</tt> sends the signal <tt>sig</tt> to the program; it returnsnon-zero if unsuccessful.<h2><a name="sb.10">B.10 Date and Time Functions: &lt;time.h&gt;</a></h2>The header <tt>&lt;time.h&gt;</tt> declares types and functions for manipulating dateand time. Some functions process <em>local time</em>, which may differ fromcalendar time, for example because of time zone. <tt>clock_t</tt> and<tt>time_t</tt> are arithmetic types representing times, and <tt>struct tm</tt>holds the components of a calendar time:<p><table align="center"><td><tt>int tm_sec;  </tt></td><td>seconds after the minute (0,61)</td><tr><td><tt>int tm_min;  </tt></td><td>minutes after the hour (0,59)</td><tr><td><tt>int tm_hour; </tt></td><td>hours since midnight (0,23)</td><tr><td><tt>int tm_mday; </tt></td><td>day of the month (1,31)</td><tr><td><tt>int tm_mon;  </tt></td><td>months <em>since</em> January (0,11)</td><tr><td><tt>int tm_year; </tt></td><td>years since 1900</td><tr><td><tt>int tm_wday; </tt></td><td>days since Sunday (0,6)</td><tr><td><tt>int tm_yday; </tt></td><td>days since January 1 (0,365)</td><tr><td><tt>int tm_isdst;</tt></td><td>Daylight Saving Time flag</td></table><p><tt>tm_isdst</tt> is positive if Daylight Saving Time is in effect, zero ifnot, and negative if the information is not available.<p><dl><p><dt><tt>clock_t clock(void)</tt><dd><tt>clock</tt> returns the processor time used by the program since thebeginning of execution, or <tt>-1</tt> if unavailable. <tt>clock()/CLK_PER_SEC</tt>is a time in seconds.<p><dt><tt>time_t time(time_t *tp)</tt><dd><tt>time</tt> returns the current calendar time or <tt>-1</tt> if the time is notavailable. If <tt>tp</tt> is not <tt>NULL</tt>, the return value is also assignedto <tt>*tp</tt>.<p><dt><tt>double difftime(time_t time2, time_t time1)</tt><dd><tt>difftime</tt> returns <tt>time2-time1</tt> expressed in seconds.<p><dt><tt>time_t mktime(struct tm *tp)</tt><dd><tt>mktime</tt> converts the local time in the structure <tt>*tp</tt> into calendartime in the same representation used by <tt>time</tt>. The components will havevalues in the ranges shown. <tt>mktime</tt> returns the calendar time or <tt>-1</tt>if it cannot be represented.</dl>The next four functions return pointers to static objects that may beoverwritten by other calls.<dl><dt><tt>char *asctime(const struct tm *tp)</tt><dd><tt>asctime</tt< converts the time in the structure <tt>*tp</tt> into a stringof the form<pre>      Sun Jan  3 15:14:13 1988\n\0</pre><p><dt><tt>char *ctime(const time_t *tp)</tt><dd><tt>ctime</tt> converts the calendar time <tt>*tp</tt> to local time; it isequivalent to<pre>      asctime(localtime(tp)) </pre><dt><tt>struct tm *gmtime(const time_t *tp)</tt><dd><tt>gmtime</tt> converts the calendar time <tt>*tp</tt> into CoordinatedUniversal Time (UTC). It returns <tt>NULL</tt> if UTC is not available. Thename <tt>gmtime</tt> has historical significance.<p><dt><tt>struct tm *localtime(const time_t *tp)</tt><dd><tt>localtime</tt> converts the calendar time <tt>*tp</tt> into local time.<p><dt><tt>size_t strftime(char *s, size_t smax, const char *fmt, const struct tm *tp)</tt><dd><tt>strftime</tt> formats date and time information from <tt>*tp</tt> into <tt>s</tt>according to <tt>fmt</tt>, which is analogous to a <tt>printf</tt> format. Ordinarycharacters (including the terminating <tt>'\0'</tt>) are copied into<tt>s</tt>. Each %c is replaced as described below, using values appropriate forthe local environment. No more than <tt>smax</tt> characters are placed into <tt>s</tt>. <tt>strftime</tt> returns the number of characters, excluding the<tt>'\0'</tt>, or zero if more than <tt>smax</tt> characters were produced.</dl><p><table align="center"><td><tt>%a</tt></td><td>abbreviated weekday name.</td><tr><td><tt>%A</tt></td><td>full weekday name.</td><tr><td><tt>%b</tt></td><td>abbreviated month name.</td><tr><td><tt>%B</tt></td><td>full month name.</td><tr><td><tt>%c</tt></td><td>local date and time representation.</td><tr><td><tt>%d</tt></td><td>day of the month (<tt>01-31</tt>).</td><tr><td><tt>%H</tt></td><td>hour (24-hour clock) <tt>(00-23)</tt>.</td><tr><td><tt>%I</tt></td><td>hour (12-hour clock) <tt>(01-12)</tt>.</td><tr><td><tt>%j</tt></td><td>day of the year <tt>(001-366)</tt>.</td><tr><td><tt>%m</tt></td><td>month <tt>(01-12)</tt>.</td><tr><td><tt>%M</tt></td><td>minute <tt>(00-59)</tt>.</td><tr><td><tt>%p</tt></td><td>local equivalent of AM or PM.</td><tr><td><tt>%S</tt></td><td>second <tt>(00-61)</tt>.</td><tr><td><tt>%U</tt></td><td>week number of the year (Sunday as 1st day of week) <tt>(00-53)</tt>.</td><tr><td><tt>%w</tt></td><td>weekday (<tt>0-6</tt>, Sunday is 0).</td><tr><td><tt>%W</tt></td><td>week number of the year (Monday as 1st day of week) <tt>(00-53)</tt>.</td><tr><td><tt>%x</tt></td><td>local date representation.</td><tr><td><tt>%X</tt></td><td>local time representation.</td><tr><td><tt>%y</tt></td><td>year without century <tt>(00-99)</tt>.</td><tr><td><tt>%Y</tt></td><td>year with century.</td><tr><td><tt>%Z</tt></td><td>time zone name, if any.</td><tr><td><tt>%%&nbsp;&nbsp;</tt></td><td>%</td></table><h2><a name="sb.11">B.11 Implementation-defined Limits: &lt;limits.h&gt; and &lt;float.h&gt;</a></h2>The header <tt>&lt;limits.h&gt;</tt> defines constants for the sizes ofintegral types. The values below are acceptable minimum magnitudes; largervalues may be used.<p><table align="center" border=0><td><tt>CHAR_BIT&nbsp;&nbsp; </tt></td><td>8</td><td>bits in a <tt>char</tt></td><tr><td><tt>CHAR_MAX </tt></td><td><tt>UCHAR_MAX</tt> <em>or</em> <tt>SCHAR_MAX</tt>&nbsp;&nbsp;</td><td>maximum value of <tt>char</tt><tr><td><tt>CHAR_MIN </tt></td><td><tt>0</tt> <em>or</em> <tt>SCHAR_MIN</tt></td><td>maximum value of <tt>char</tt></td><tr><td><tt>INT_MAX  </tt></td><td><tt>32767</tt></td><td>maximum value of <tt>int</tt></td><tr><td><tt>INT_MIN  </tt></td><td><tt>-32767</tt></td><td>minimum value of <tt>int</tt></td><tr><td><tt>LONG_MAX </tt></td><td><tt>2147483647</tt></td><td>maximum value of <tt>long</tt></td><tr><td><tt>LONG_MIN </tt></td><td><tt>-2147483647</tt></td><td>minimum value of <tt>long</tt></td><tr><td><tt>SCHAR_MAX</tt></td><td><tt>+127</tt></td><td>maximum value of <tt>signed char</tt></td><tr><td><tt>SCHAR_MIN</tt></td><td><tt>-127</tt></td><td>minimum value of <tt>signed char</tt></td><tr><td><tt>SHRT_MAX </tt></td><td><tt>+32767</tt></td><td>maximum value of <tt>short</tt></td><tr><td><tt>SHRT_MIN </tt></td><td><tt>-32767</tt></td><td>minimum value of <tt>short</tt></td><tr><td><tt>UCHAR_MAX</tt></td><td><tt>255</tt></td><td>maximum value of <tt>unsigned char</tt></td><tr><td><tt>UINT_MAX </tt></td><td><tt>65535</tt></td><td>maximum value of <tt>unsigned int</tt></td><tr><td><tt>ULONG_MAX</tt></td><td><tt>4294967295</tt></td><td>maximum value of <tt>unsigned long</tt></td><tr><td><tt>USHRT_MAX</tt></td><td><tt>65535</tt></td><td>maximum value of <tt>unsigned short</tt></td></table><p>The names in the table below, a subset of <tt>&lt;float.h&gt;</tt>, are constantsrelated to floating-point arithmetic. When a value is given, it representsthe minimum magnitude for the corresponding quantity. Each implementationdefines appropriate values.<p><table align="center" border=0><td><tt>FLT_RADIX   </tt></td><td><tt>2</tt></td><td>radix of exponent, representation, e.g., 2, 16</td><tr><td><tt>FLT_ROUNDS  </tt></td><td></td>          <td>floating-point rounding mode for addition</td><tr><td><tt>FLT_DIG     </tt></td><td><tt>6</tt></td><td>decimal digits of precision</td><tr><td><tt>FLT_EPSILON </tt></td><td><tt>1E-5</tt></td><td>smallest number <em>x</em> such that 1.0+x != 1.0</td><tr><td><tt>FLT_MANT_DIG&nbsp;&nbsp;</tt></td><td></td><td>number of base <tt>FLT_RADIX</tt> in mantissa</td><tr><td><tt>FLT_MAX     </tt></td><td><tt>1E+37&nbsp;&nbsp;</tt></td><td>maximum floating-point number</td><tr><td><tt>FLT_MAX_EXP </tt></td><td></td><td>maximum <em>n</em> such that <tt>FLT_RADIX</tt><sup>n-1</sup> is representable</td><tr><td><tt>FLT_MIN     </tt></td><td><tt>1E-37</tt></td><td>minimum normalized floating-point number</td><tr><td><tt>FLT_MIN_EXP </tt></td><td></td><td>minimum <em>n</em> such that 10<sup><em>n</em></sup> is a normalized number</td><tr><td><tt>DBL_DIG     </tt></td><td><tt>10</tt></td><td>decimal digits of precision</td><tr><td><tt>DBL_EPSILON </tt></td><td><tt>1E-9</tt></td><td>smallest number <em>x</em> such that 1.0+x != 1.0</td><tr><td><tt>DBL_MANT_DIG</tt></td><td></td><td>number of base <tt>FLT_RADIX</tt> in mantissa</td><tr><td><tt>DBL_MAX     </tt></td><td><tt>1E+37</tt></td><td>maximum <tt>double</tt> floating-point number</td><tr><td><tt>DBL_MAX_EXP </tt></td><td></td><td>maximum <em>n</em> such that <tt>FLT_RADIX</tt><sup>n-1</sup> is representable</td><tr><td><tt>DBL_MIN     </tt></td><td><tt>1E-37</tt></td><td>minimum normalized <tt>double</tt> floating-point number</td><tr><td><tt>DBL_MIN_EXP </tt></td><td></td><td>minimum <em>n</em> such that 10<sup><em>n</em></sup> is a normalized number</td></table><p><hr><p align="center"><a href="appa.html">Back to Appendix A</a>&nbsp;--&nbsp;<a href="kandr.html">Index</a>&nbsp;--&nbsp;<a href="appc.html">Appendix C</a><p><hr></body></html>

⌨️ 快捷键说明

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