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

📄 incompatibilities.html

📁 gcc手册
💻 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.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,

1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.2 or

any later version published by the Free Software Foundation; with the

Invariant Sections being "GNU General Public License" and "Funding

Free Software", the Front-Cover texts being (a) (see below), and with

the Back-Cover Texts being (b) (see below).  A copy of the license is

included 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.-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Incompatibilities">Incompatibilities</a>,

Next:<a rel="next" accesskey="n" href="Fixed-Headers.html#Fixed%20Headers">Fixed Headers</a>,

Previous:<a rel="previous" accesskey="p" href="External-Bugs.html#External%20Bugs">External Bugs</a>,

Up:<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 several

identical-looking string constants are used, GCC stores only one

copy of the string.



     <p>One consequence is that you cannot call <code>mktemp</code> with a string

constant argument.  The function <code>mktemp</code> always alters the

string its argument points to.



     <p>Another consequence is that <code>sscanf</code> does not work on some systems

when passed a string constant as its format control string or input. 

This is because <code>sscanf</code> incorrectly tries to write into the string

constant.  Likewise <code>fscanf</code> and <code>scanf</code>.



     <p>The best solution to these problems is to change the program to use

<code>char</code>-array variables with initialization strings for these

purposes instead of string constants.  But if this is not possible,

you can use the <code>-fwritable-strings</code> flag, which directs GCC

to handle string constants the same way most C compilers do.



     </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 of

string constants.  For example, the following macro in GCC



     <pre class="example">          #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 automatic

variables guaranteed to remain valid are those declared

<code>volatile</code>.  This is a consequence of automatic register

allocation.  Consider this function:



     <pre class="example">          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, then

its first value is restored; otherwise, it keeps the last value stored

in it.



     <p>If you use the <code>-W</code> option with the <code>-O</code> option, you will

get a warning when GCC thinks such a problem might be possible.



     </p><li>Programs that use preprocessing directives in the middle of macro

arguments do not work with GCC.  For example, a program like this

will not work:



     <pre class="example">          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 think

this would be quite ugly and can't imagine it could be needed.



     <li>Declarations of external variables and functions within a block apply

only to the block containing the declaration.  In other words, they

have the same scope as any other declaration in the same place.



     <p>In some other C compilers, a <code>extern</code> declaration affects all the

rest 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="example">          typedef int foo;

          typedef long foo bar;

          </pre>



     <p>In ISO C, this is not allowed: <code>long</code> and other type modifiers

require 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 to

appear together in a given scope:



     <pre class="example">          typedef int foo;

          typedef foo foo;

          </pre>



     <li>GCC treats all characters of identifiers as significant.  According to

K&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), "An

identifier is a sequence of letters and digits; the first character must

be a letter.  The underscore _ counts as a letter.", but GCC also

allows dollar signs in identifiers.



     <li>PCC allows whitespace in the middle of compound assignment operators

such as <code>+=</code>.  GCC, following the ISO standard, does not

allow this.



     <li>GCC complains about unterminated character constants inside of

preprocessing conditionals that fail.  Some programs have English

comments enclosed in conditionals that are guaranteed to fail; if these

comments contain apostrophes, GCC will probably report an error.  For

example, this code would produce an error:



     <pre class="example">          #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 actual

C comment delimited by <code>/*...*/</code>.



     </p><li>Many user programs contain the declaration <code>long time ();</code>.  In the

past, 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 to

return.  But in systems with ISO C headers, <code>time</code> is declared to

return <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 to

use <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 to

a double.  GCC actually returns a <code>float</code>.  If you are concerned

with 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, GCC

output code normally uses a method different from that used on most

versions of Unix.  As a result, code compiled with GCC cannot call

a structure-returning function compiled with PCC, and vice versa.



     <p>The method used by GCC is as follows: a structure or union which is

1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or union

with any other size is stored into an address supplied by the caller

(usually in a special, fixed register, but on some machines it is passed

on the stack).  The machine-description macros <code>STRUCT_VALUE</code> and

<code>STRUCT_INCOMING_VALUE</code> tell GCC where to pass this address.



     <p>By contrast, PCC on most target machines returns structures and unions

of any size by copying the data into an area of static storage, and then

returning 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 where

the value is wanted.  GCC does not use this method because it is

slower and nonreentrant.



     <p>On some newer machines, PCC uses a reentrant convention for all

structure and union returning.  GCC on most of these machines uses a

compatible 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 and

union 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 minus

operator.  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 what

is meant is an operator and two values, the ISO C standard specifically

requires that this be treated as erroneous.



     <p>A <dfn>preprocessing token</dfn> is a <dfn>preprocessing number</dfn> if it

begins 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 C89

mode, the sequences <code>p+</code>, <code>p-</code>, <code>P+</code> and <code>P-</code> cannot

appear in preprocessing numbers.)



     <p>To make the above program fragment valid, place whitespace in front of

the minus sign.  This whitespace will end the preprocessing number. 

</ul>



   </body></html>



⌨️ 快捷键说明

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