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

📄 incompatibilities.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
字号:
<html lang="en"><head><title>Using the GNU Compiler Collection (GCC)</title><meta http-equiv="Content-Type" content="text/html"><meta name="description" content="Using the GNU Compiler Collection (GCC)"><meta name="generator" content="makeinfo 4.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded in the section entitled "GNU Free Documentation License".   <p>(a) The FSF's Front-Cover Text is:   <p>A GNU Manual   <p>(b) The FSF's Back-Cover Text is:   <p>You have freedom to copy and modify this GNU Manual, like GNU     software.  Copies published by the Free Software Foundation raise     funds for GNU development.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Incompatibilities">Incompatibilities</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Fixed-Headers.html#Fixed%20Headers">Fixed Headers</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="External-Bugs.html#External%20Bugs">External Bugs</a>,Up:&nbsp;<a rel="up" accesskey="u" href="Trouble.html#Trouble">Trouble</a><hr><br></div><h3 class="section">Incompatibilities of GCC</h3><p>There are several noteworthy incompatibilities between GNU C and K&amp;R(non-ISO) versions of C.     <ul><li>GCC normally makes string constants read-only.  If severalidentical-looking string constants are used, GCC stores only onecopy of the string.     <p>One consequence is that you cannot call <code>mktemp</code> with a stringconstant argument.  The function <code>mktemp</code> always alters thestring its argument points to.     <p>Another consequence is that <code>sscanf</code> does not work on some veryold systems when passed a string constant as its format control stringor input.  This is because <code>sscanf</code> incorrectly tries to writeinto the string constant.  Likewise <code>fscanf</code> and <code>scanf</code>.     <p>The solution to these problems is to change the program to use<code>char</code>-array variables with initialization strings for thesepurposes instead of string constants.     </p><li><code>-2147483648</code> is positive.     <p>This is because 2147483648 cannot fit in the type <code>int</code>, so(following the ISO C rules) its data type is <code>unsigned long int</code>. Negating this value yields 2147483648 again.     </p><li>GCC does not substitute macro arguments when they appear inside ofstring constants.  For example, the following macro in GCC     <pre class="smallexample">          #define foo(a) "a"          </pre>     <p>will produce output <code>"a"</code> regardless of what the argument <var>a</var> is.     </p><li>When you use <code>setjmp</code> and <code>longjmp</code>, the only automaticvariables guaranteed to remain valid are those declared<code>volatile</code>.  This is a consequence of automatic registerallocation.  Consider this function:     <pre class="smallexample">          jmp_buf j;                    foo ()          {            int a, b;                      a = fun1 ();            if (setjmp (j))              return a;                      a = fun2 ();            /* <code>longjmp (j)</code> may occur in <code>fun3</code>. */            return a + fun3 ();          }          </pre>     <p>Here <code>a</code> may or may not be restored to its first value when the<code>longjmp</code> occurs.  If <code>a</code> is allocated in a register, thenits first value is restored; otherwise, it keeps the last value storedin it.     <p>If you use the <code>-W</code> option with the <code>-O</code> option, you willget a warning when GCC thinks such a problem might be possible.     </p><li>Programs that use preprocessing directives in the middle of macroarguments do not work with GCC.  For example, a program like thiswill not work:     <pre class="smallexample">          foobar (          #define luser                  hack)          </pre>     <p>ISO C does not permit such a construct.     </p><li>K&amp;R compilers allow comments to cross over an inclusion boundary(i.e. started in an include file and ended in the including file).  I thinkthis would be quite ugly and can't imagine it could be needed.     <li>Declarations of external variables and functions within a block applyonly to the block containing the declaration.  In other words, theyhave the same scope as any other declaration in the same place.     <p>In some other C compilers, a <code>extern</code> declaration affects all therest of the file even if it happens within a block.     </p><li>In traditional C, you can combine <code>long</code>, etc., with a typedef name,as shown here:     <pre class="smallexample">          typedef int foo;          typedef long foo bar;          </pre>     <p>In ISO C, this is not allowed: <code>long</code> and other type modifiersrequire an explicit <code>int</code>.     </p><li>PCC allows typedef names to be used as function parameters.     <li>Traditional C allows the following erroneous pair of declarations toappear together in a given scope:     <pre class="smallexample">          typedef int foo;          typedef foo foo;          </pre>     <li>GCC treats all characters of identifiers as significant.  According toK&amp;R-1 (2.2), "No more than the first eight characters are significant,although more may be used.".  Also according to K&amp;R-1 (2.2), "Anidentifier is a sequence of letters and digits; the first character mustbe a letter.  The underscore _ counts as a letter.", but GCC alsoallows dollar signs in identifiers.     <li>PCC allows whitespace in the middle of compound assignment operatorssuch as <code>+=</code>.  GCC, following the ISO standard, does notallow this.     <li>GCC complains about unterminated character constants inside ofpreprocessing conditionals that fail.  Some programs have Englishcomments enclosed in conditionals that are guaranteed to fail; if thesecomments contain apostrophes, GCC will probably report an error.  Forexample, this code would produce an error:     <pre class="smallexample">          #if 0          You can't expect this to work.          #endif          </pre>     <p>The best solution to such a problem is to put the text into an actualC comment delimited by <code>/*...*/</code>.     </p><li>Many user programs contain the declaration <code>long time ();</code>.  In thepast, the system header files on many systems did not actually declare<code>time</code>, so it did not matter what type your program declared it toreturn.  But in systems with ISO C headers, <code>time</code> is declared toreturn <code>time_t</code>, and if that is not the same as <code>long</code>, then<code>long time ();</code> is erroneous.     <p>The solution is to change your program to use appropriate system headers(<code>&lt;time.h&gt;</code> on systems with ISO C headers) and not to declare<code>time</code> if the system header files declare it, or failing that touse <code>time_t</code> as the return type of <code>time</code>.     </p><li>When compiling functions that return <code>float</code>, PCC converts it toa double.  GCC actually returns a <code>float</code>.  If you are concernedwith PCC compatibility, you should declare your functions to return<code>double</code>; you might as well say what you mean.     <li>When compiling functions that return structures or unions, GCCoutput code normally uses a method different from that used on mostversions of Unix.  As a result, code compiled with GCC cannot calla structure-returning function compiled with PCC, and vice versa.     <p>The method used by GCC is as follows: a structure or union which is1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or unionwith any other size is stored into an address supplied by the caller(usually in a special, fixed register, but on some machines it is passedon the stack).  The target hook <code>TARGET_STRUCT_VALUE_RTX</code>tells GCC where to pass this address.     <p>By contrast, PCC on most target machines returns structures and unionsof any size by copying the data into an area of static storage, and thenreturning the address of that storage as if it were a pointer value. The caller must copy the data from that memory area to the place wherethe value is wanted.  GCC does not use this method because it isslower and nonreentrant.     <p>On some newer machines, PCC uses a reentrant convention for allstructure and union returning.  GCC on most of these machines uses acompatible convention when returning structures and unions in memory,but still returns small structures and unions in registers.     <p>You can tell GCC to use a compatible convention for all structure andunion returning with the option <code>-fpcc-struct-return</code>.     </p><li>GCC complains about program fragments such as <code>0x74ae-0x4000</code>which appear to be two hexadecimal constants separated by the minusoperator.  Actually, this string is a single <dfn>preprocessing token</dfn>. Each such token must correspond to one token in C.  Since this does not,GCC prints an error message.  Although it may appear obvious that whatis meant is an operator and two values, the ISO C standard specificallyrequires that this be treated as erroneous.     <p>A <dfn>preprocessing token</dfn> is a <dfn>preprocessing number</dfn> if itbegins with a digit and is followed by letters, underscores, digits,periods and <code>e+</code>, <code>e-</code>, <code>E+</code>, <code>E-</code>, <code>p+</code>,<code>p-</code>, <code>P+</code>, or <code>P-</code> character sequences.  (In strict C89mode, the sequences <code>p+</code>, <code>p-</code>, <code>P+</code> and <code>P-</code> cannotappear in preprocessing numbers.)     <p>To make the above program fragment valid, place whitespace in front ofthe minus sign.  This whitespace will end the preprocessing number. </ul>   </body></html>

⌨️ 快捷键说明

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