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