您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

312 行
14KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Incompatibilities (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Incompatibilities (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Incompatibilities (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Trouble.html#Trouble" rel="up" title="Trouble">
  30. <link href="Fixed-Headers.html#Fixed-Headers" rel="next" title="Fixed Headers">
  31. <link href="Interoperation.html#Interoperation" rel="prev" title="Interoperation">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Incompatibilities"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Fixed-Headers.html#Fixed-Headers" accesskey="n" rel="next">Fixed Headers</a>, Previous: <a href="Interoperation.html#Interoperation" accesskey="p" rel="prev">Interoperation</a>, Up: <a href="Trouble.html#Trouble" accesskey="u" rel="up">Trouble</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Incompatibilities-of-GCC"></a>
  68. <h3 class="section">14.3 Incompatibilities of GCC</h3>
  69. <a name="index-incompatibilities-of-GCC"></a>
  70. <a name="index-traditional-1"></a>
  71. <p>There are several noteworthy incompatibilities between GNU C and K&amp;R
  72. (non-ISO) versions of C.
  73. </p>
  74. <ul>
  75. <li> <a name="index-string-constants"></a>
  76. <a name="index-read_002donly-strings"></a>
  77. <a name="index-shared-strings"></a>
  78. GCC normally makes string constants read-only. If several
  79. identical-looking string constants are used, GCC stores only one
  80. copy of the string.
  81. <a name="index-mktemp_002c-and-constant-strings"></a>
  82. <p>One consequence is that you cannot call <code>mktemp</code> with a string
  83. constant argument. The function <code>mktemp</code> always alters the
  84. string its argument points to.
  85. </p>
  86. <a name="index-sscanf_002c-and-constant-strings"></a>
  87. <a name="index-fscanf_002c-and-constant-strings"></a>
  88. <a name="index-scanf_002c-and-constant-strings"></a>
  89. <p>Another consequence is that <code>sscanf</code> does not work on some very
  90. old systems when passed a string constant as its format control string
  91. or input. This is because <code>sscanf</code> incorrectly tries to write
  92. into the string constant. Likewise <code>fscanf</code> and <code>scanf</code>.
  93. </p>
  94. <p>The solution to these problems is to change the program to use
  95. <code>char</code>-array variables with initialization strings for these
  96. purposes instead of string constants.
  97. </p>
  98. </li><li> <code>-2147483648</code> is positive.
  99. <p>This is because 2147483648 cannot fit in the type <code>int</code>, so
  100. (following the ISO C rules) its data type is <code>unsigned long int</code>.
  101. Negating this value yields 2147483648 again.
  102. </p>
  103. </li><li> GCC does not substitute macro arguments when they appear inside of
  104. string constants. For example, the following macro in GCC
  105. <div class="smallexample">
  106. <pre class="smallexample">#define foo(a) &quot;a&quot;
  107. </pre></div>
  108. <p>will produce output <code>&quot;a&quot;</code> regardless of what the argument <var>a</var> is.
  109. </p>
  110. </li><li> <a name="index-setjmp-incompatibilities"></a>
  111. <a name="index-longjmp-incompatibilities"></a>
  112. When you use <code>setjmp</code> and <code>longjmp</code>, the only automatic
  113. variables guaranteed to remain valid are those declared
  114. <code>volatile</code>. This is a consequence of automatic register
  115. allocation. Consider this function:
  116. <div class="smallexample">
  117. <pre class="smallexample">jmp_buf j;
  118. foo ()
  119. {
  120. int a, b;
  121. a = fun1 ();
  122. if (setjmp (j))
  123. return a;
  124. a = fun2 ();
  125. /* <span class="roman"><code>longjmp (j)</code> may occur in <code>fun3</code>.</span> */
  126. return a + fun3 ();
  127. }
  128. </pre></div>
  129. <p>Here <code>a</code> may or may not be restored to its first value when the
  130. <code>longjmp</code> occurs. If <code>a</code> is allocated in a register, then
  131. its first value is restored; otherwise, it keeps the last value stored
  132. in it.
  133. </p>
  134. <a name="index-W-3"></a>
  135. <p>If you use the <samp>-W</samp> option with the <samp>-O</samp> option, you will
  136. get a warning when GCC thinks such a problem might be possible.
  137. </p>
  138. </li><li> Programs that use preprocessing directives in the middle of macro
  139. arguments do not work with GCC. For example, a program like this
  140. will not work:
  141. <div class="smallexample">
  142. <pre class="smallexample">foobar (
  143. #define luser
  144. hack)
  145. </pre></div>
  146. <p>ISO C does not permit such a construct.
  147. </p>
  148. </li><li> K&amp;R compilers allow comments to cross over an inclusion boundary
  149. (i.e. started in an include file and ended in the including file).
  150. </li><li> <a name="index-external-declaration-scope"></a>
  151. <a name="index-scope-of-external-declarations"></a>
  152. <a name="index-declaration-scope"></a>
  153. Declarations of external variables and functions within a block apply
  154. only to the block containing the declaration. In other words, they
  155. have the same scope as any other declaration in the same place.
  156. <p>In some other C compilers, an <code>extern</code> declaration affects all the
  157. rest of the file even if it happens within a block.
  158. </p>
  159. </li><li> In traditional C, you can combine <code>long</code>, etc., with a typedef name,
  160. as shown here:
  161. <div class="smallexample">
  162. <pre class="smallexample">typedef int foo;
  163. typedef long foo bar;
  164. </pre></div>
  165. <p>In ISO C, this is not allowed: <code>long</code> and other type modifiers
  166. require an explicit <code>int</code>.
  167. </p>
  168. </li><li> <a name="index-typedef-names-as-function-parameters"></a>
  169. PCC allows typedef names to be used as function parameters.
  170. </li><li> Traditional C allows the following erroneous pair of declarations to
  171. appear together in a given scope:
  172. <div class="smallexample">
  173. <pre class="smallexample">typedef int foo;
  174. typedef foo foo;
  175. </pre></div>
  176. </li><li> GCC treats all characters of identifiers as significant. According to
  177. K&amp;R-1 (2.2), &ldquo;No more than the first eight characters are significant,
  178. although more may be used.&rdquo;. Also according to K&amp;R-1 (2.2), &ldquo;An
  179. identifier is a sequence of letters and digits; the first character must
  180. be a letter. The underscore _ counts as a letter.&rdquo;, but GCC also
  181. allows dollar signs in identifiers.
  182. </li><li> <a name="index-whitespace"></a>
  183. PCC allows whitespace in the middle of compound assignment operators
  184. such as &lsquo;<samp>+=</samp>&rsquo;. GCC, following the ISO standard, does not
  185. allow this.
  186. </li><li> <a name="index-apostrophes"></a>
  187. <a name="index-_0027"></a>
  188. GCC complains about unterminated character constants inside of
  189. preprocessing conditionals that fail. Some programs have English
  190. comments enclosed in conditionals that are guaranteed to fail; if these
  191. comments contain apostrophes, GCC will probably report an error. For
  192. example, this code would produce an error:
  193. <div class="smallexample">
  194. <pre class="smallexample">#if 0
  195. You can't expect this to work.
  196. #endif
  197. </pre></div>
  198. <p>The best solution to such a problem is to put the text into an actual
  199. C comment delimited by &lsquo;<samp>/*&hellip;*/</samp>&rsquo;.
  200. </p>
  201. </li><li> Many user programs contain the declaration &lsquo;<samp>long time ();</samp>&rsquo;. In the
  202. past, the system header files on many systems did not actually declare
  203. <code>time</code>, so it did not matter what type your program declared it to
  204. return. But in systems with ISO C headers, <code>time</code> is declared to
  205. return <code>time_t</code>, and if that is not the same as <code>long</code>, then
  206. &lsquo;<samp>long time ();</samp>&rsquo; is erroneous.
  207. <p>The solution is to change your program to use appropriate system headers
  208. (<code>&lt;time.h&gt;</code> on systems with ISO C headers) and not to declare
  209. <code>time</code> if the system header files declare it, or failing that to
  210. use <code>time_t</code> as the return type of <code>time</code>.
  211. </p>
  212. </li><li> <a name="index-float-as-function-value-type"></a>
  213. When compiling functions that return <code>float</code>, PCC converts it to
  214. a double. GCC actually returns a <code>float</code>. If you are concerned
  215. with PCC compatibility, you should declare your functions to return
  216. <code>double</code>; you might as well say what you mean.
  217. </li><li> <a name="index-structures"></a>
  218. <a name="index-unions"></a>
  219. When compiling functions that return structures or unions, GCC
  220. output code normally uses a method different from that used on most
  221. versions of Unix. As a result, code compiled with GCC cannot call
  222. a structure-returning function compiled with PCC, and vice versa.
  223. <p>The method used by GCC is as follows: a structure or union which is
  224. 1, 2, 4 or 8 bytes long is returned like a scalar. A structure or union
  225. with any other size is stored into an address supplied by the caller
  226. (usually in a special, fixed register, but on some machines it is passed
  227. on the stack). The target hook <code>TARGET_STRUCT_VALUE_RTX</code>
  228. tells GCC where to pass this address.
  229. </p>
  230. <p>By contrast, PCC on most target machines returns structures and unions
  231. of any size by copying the data into an area of static storage, and then
  232. returning the address of that storage as if it were a pointer value.
  233. The caller must copy the data from that memory area to the place where
  234. the value is wanted. GCC does not use this method because it is
  235. slower and nonreentrant.
  236. </p>
  237. <p>On some newer machines, PCC uses a reentrant convention for all
  238. structure and union returning. GCC on most of these machines uses a
  239. compatible convention when returning structures and unions in memory,
  240. but still returns small structures and unions in registers.
  241. </p>
  242. <a name="index-fpcc_002dstruct_002dreturn-1"></a>
  243. <p>You can tell GCC to use a compatible convention for all structure and
  244. union returning with the option <samp>-fpcc-struct-return</samp>.
  245. </p>
  246. </li><li> <a name="index-preprocessing-tokens"></a>
  247. <a name="index-preprocessing-numbers"></a>
  248. GCC complains about program fragments such as &lsquo;<samp>0x74ae-0x4000</samp>&rsquo;
  249. which appear to be two hexadecimal constants separated by the minus
  250. operator. Actually, this string is a single <em>preprocessing token</em>.
  251. Each such token must correspond to one token in C. Since this does not,
  252. GCC prints an error message. Although it may appear obvious that what
  253. is meant is an operator and two values, the ISO C standard specifically
  254. requires that this be treated as erroneous.
  255. <p>A <em>preprocessing token</em> is a <em>preprocessing number</em> if it
  256. begins with a digit and is followed by letters, underscores, digits,
  257. periods and &lsquo;<samp>e+</samp>&rsquo;, &lsquo;<samp>e-</samp>&rsquo;, &lsquo;<samp>E+</samp>&rsquo;, &lsquo;<samp>E-</samp>&rsquo;, &lsquo;<samp>p+</samp>&rsquo;,
  258. &lsquo;<samp>p-</samp>&rsquo;, &lsquo;<samp>P+</samp>&rsquo;, or &lsquo;<samp>P-</samp>&rsquo; character sequences. (In strict C90
  259. mode, the sequences &lsquo;<samp>p+</samp>&rsquo;, &lsquo;<samp>p-</samp>&rsquo;, &lsquo;<samp>P+</samp>&rsquo; and &lsquo;<samp>P-</samp>&rsquo; cannot
  260. appear in preprocessing numbers.)
  261. </p>
  262. <p>To make the above program fragment valid, place whitespace in front of
  263. the minus sign. This whitespace will end the preprocessing number.
  264. </p></li></ul>
  265. <hr>
  266. <div class="header">
  267. <p>
  268. Next: <a href="Fixed-Headers.html#Fixed-Headers" accesskey="n" rel="next">Fixed Headers</a>, Previous: <a href="Interoperation.html#Interoperation" accesskey="p" rel="prev">Interoperation</a>, Up: <a href="Trouble.html#Trouble" accesskey="u" rel="up">Trouble</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  269. </div>
  270. </body>
  271. </html>