You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

315 lines
15KB

  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>Non-bugs (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Non-bugs (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Non-bugs (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="Warnings-and-Errors.html#Warnings-and-Errors" rel="next" title="Warnings and Errors">
  31. <link href="Copy-Assignment.html#Copy-Assignment" rel="prev" title="Copy Assignment">
  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="Non_002dbugs"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Warnings-and-Errors.html#Warnings-and-Errors" accesskey="n" rel="next">Warnings and Errors</a>, Previous: <a href="C_002b_002b-Misunderstandings.html#C_002b_002b-Misunderstandings" accesskey="p" rel="prev">C++ Misunderstandings</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="Certain-Changes-We-Don_0027t-Want-to-Make"></a>
  68. <h3 class="section">14.8 Certain Changes We Don&rsquo;t Want to Make</h3>
  69. <p>This section lists changes that people frequently request, but which
  70. we do not make because we think GCC is better without them.
  71. </p>
  72. <ul>
  73. <li> Checking the number and type of arguments to a function which has an
  74. old-fashioned definition and no prototype.
  75. <p>Such a feature would work only occasionally&mdash;only for calls that appear
  76. in the same file as the called function, following the definition. The
  77. only way to check all calls reliably is to add a prototype for the
  78. function. But adding a prototype eliminates the motivation for this
  79. feature. So the feature is not worthwhile.
  80. </p>
  81. </li><li> Warning about using an expression whose type is signed as a shift count.
  82. <p>Shift count operands are probably signed more often than unsigned.
  83. Warning about this would cause far more annoyance than good.
  84. </p>
  85. </li><li> Warning about assigning a signed value to an unsigned variable.
  86. <p>Such assignments must be very common; warning about them would cause
  87. more annoyance than good.
  88. </p>
  89. </li><li> Warning when a non-void function value is ignored.
  90. <p>C contains many standard functions that return a value that most
  91. programs choose to ignore. One obvious example is <code>printf</code>.
  92. Warning about this practice only leads the defensive programmer to
  93. clutter programs with dozens of casts to <code>void</code>. Such casts are
  94. required so frequently that they become visual noise. Writing those
  95. casts becomes so automatic that they no longer convey useful
  96. information about the intentions of the programmer. For functions
  97. where the return value should never be ignored, use the
  98. <code>warn_unused_result</code> function attribute (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>).
  99. </p>
  100. </li><li> <a name="index-fshort_002denums-3"></a>
  101. Making <samp>-fshort-enums</samp> the default.
  102. <p>This would cause storage layout to be incompatible with most other C
  103. compilers. And it doesn&rsquo;t seem very important, given that you can get
  104. the same result in other ways. The case where it matters most is when
  105. the enumeration-valued object is inside a structure, and in that case
  106. you can specify a field width explicitly.
  107. </p>
  108. </li><li> Making bit-fields unsigned by default on particular machines where &ldquo;the
  109. ABI standard&rdquo; says to do so.
  110. <p>The ISO C standard leaves it up to the implementation whether a bit-field
  111. declared plain <code>int</code> is signed or not. This in effect creates two
  112. alternative dialects of C.
  113. </p>
  114. <a name="index-fsigned_002dbitfields-1"></a>
  115. <a name="index-funsigned_002dbitfields-2"></a>
  116. <p>The GNU C compiler supports both dialects; you can specify the signed
  117. dialect with <samp>-fsigned-bitfields</samp> and the unsigned dialect with
  118. <samp>-funsigned-bitfields</samp>. However, this leaves open the question of
  119. which dialect to use by default.
  120. </p>
  121. <p>Currently, the preferred dialect makes plain bit-fields signed, because
  122. this is simplest. Since <code>int</code> is the same as <code>signed int</code> in
  123. every other context, it is cleanest for them to be the same in bit-fields
  124. as well.
  125. </p>
  126. <p>Some computer manufacturers have published Application Binary Interface
  127. standards which specify that plain bit-fields should be unsigned. It is
  128. a mistake, however, to say anything about this issue in an ABI. This is
  129. because the handling of plain bit-fields distinguishes two dialects of C.
  130. Both dialects are meaningful on every type of machine. Whether a
  131. particular object file was compiled using signed bit-fields or unsigned
  132. is of no concern to other object files, even if they access the same
  133. bit-fields in the same data structures.
  134. </p>
  135. <p>A given program is written in one or the other of these two dialects.
  136. The program stands a chance to work on most any machine if it is
  137. compiled with the proper dialect. It is unlikely to work at all if
  138. compiled with the wrong dialect.
  139. </p>
  140. <p>Many users appreciate the GNU C compiler because it provides an
  141. environment that is uniform across machines. These users would be
  142. inconvenienced if the compiler treated plain bit-fields differently on
  143. certain machines.
  144. </p>
  145. <p>Occasionally users write programs intended only for a particular machine
  146. type. On these occasions, the users would benefit if the GNU C compiler
  147. were to support by default the same dialect as the other compilers on
  148. that machine. But such applications are rare. And users writing a
  149. program to run on more than one type of machine cannot possibly benefit
  150. from this kind of compatibility.
  151. </p>
  152. <p>This is why GCC does and will treat plain bit-fields in the same
  153. fashion on all types of machines (by default).
  154. </p>
  155. <p>There are some arguments for making bit-fields unsigned by default on all
  156. machines. If, for example, this becomes a universal de facto standard,
  157. it would make sense for GCC to go along with it. This is something
  158. to be considered in the future.
  159. </p>
  160. <p>(Of course, users strongly concerned about portability should indicate
  161. explicitly in each bit-field whether it is signed or not. In this way,
  162. they write programs which have the same meaning in both C dialects.)
  163. </p>
  164. </li><li> <a name="index-ansi-3"></a>
  165. <a name="index-std-3"></a>
  166. Undefining <code>__STDC__</code> when <samp>-ansi</samp> is not used.
  167. <p>Currently, GCC defines <code>__STDC__</code> unconditionally. This provides
  168. good results in practice.
  169. </p>
  170. <p>Programmers normally use conditionals on <code>__STDC__</code> to ask whether
  171. it is safe to use certain features of ISO C, such as function
  172. prototypes or ISO token concatenation. Since plain <code>gcc</code> supports
  173. all the features of ISO C, the correct answer to these questions is
  174. &ldquo;yes&rdquo;.
  175. </p>
  176. <p>Some users try to use <code>__STDC__</code> to check for the availability of
  177. certain library facilities. This is actually incorrect usage in an ISO
  178. C program, because the ISO C standard says that a conforming
  179. freestanding implementation should define <code>__STDC__</code> even though it
  180. does not have the library facilities. &lsquo;<samp>gcc -ansi -pedantic</samp>&rsquo; is a
  181. conforming freestanding implementation, and it is therefore required to
  182. define <code>__STDC__</code>, even though it does not come with an ISO C
  183. library.
  184. </p>
  185. <p>Sometimes people say that defining <code>__STDC__</code> in a compiler that
  186. does not completely conform to the ISO C standard somehow violates the
  187. standard. This is illogical. The standard is a standard for compilers
  188. that claim to support ISO C, such as &lsquo;<samp>gcc -ansi</samp>&rsquo;&mdash;not for other
  189. compilers such as plain <code>gcc</code>. Whatever the ISO C standard says
  190. is relevant to the design of plain <code>gcc</code> without <samp>-ansi</samp> only
  191. for pragmatic reasons, not as a requirement.
  192. </p>
  193. <p>GCC normally defines <code>__STDC__</code> to be 1, and in addition
  194. defines <code>__STRICT_ANSI__</code> if you specify the <samp>-ansi</samp> option,
  195. or a <samp>-std</samp> option for strict conformance to some version of ISO C.
  196. On some hosts, system include files use a different convention, where
  197. <code>__STDC__</code> is normally 0, but is 1 if the user specifies strict
  198. conformance to the C Standard. GCC follows the host convention when
  199. processing system include files, but when processing user files it follows
  200. the usual GNU C convention.
  201. </p>
  202. </li><li> Undefining <code>__STDC__</code> in C++.
  203. <p>Programs written to compile with C++-to-C translators get the
  204. value of <code>__STDC__</code> that goes with the C compiler that is
  205. subsequently used. These programs must test <code>__STDC__</code>
  206. to determine what kind of C preprocessor that compiler uses:
  207. whether they should concatenate tokens in the ISO C fashion
  208. or in the traditional fashion.
  209. </p>
  210. <p>These programs work properly with GNU C++ if <code>__STDC__</code> is defined.
  211. They would not work otherwise.
  212. </p>
  213. <p>In addition, many header files are written to provide prototypes in ISO
  214. C but not in traditional C. Many of these header files can work without
  215. change in C++ provided <code>__STDC__</code> is defined. If <code>__STDC__</code>
  216. is not defined, they will all fail, and will all need to be changed to
  217. test explicitly for C++ as well.
  218. </p>
  219. </li><li> Deleting &ldquo;empty&rdquo; loops.
  220. <p>Historically, GCC has not deleted &ldquo;empty&rdquo; loops under the
  221. assumption that the most likely reason you would put one in a program is
  222. to have a delay, so deleting them will not make real programs run any
  223. faster.
  224. </p>
  225. <p>However, the rationale here is that optimization of a nonempty loop
  226. cannot produce an empty one. This held for carefully written C compiled
  227. with less powerful optimizers but is not always the case for carefully
  228. written C++ or with more powerful optimizers.
  229. Thus GCC will remove operations from loops whenever it can determine
  230. those operations are not externally visible (apart from the time taken
  231. to execute them, of course). In case the loop can be proved to be finite,
  232. GCC will also remove the loop itself.
  233. </p>
  234. <p>Be aware of this when performing timing tests, for instance the
  235. following loop can be completely removed, provided
  236. <code>some_expression</code> can provably not change any global state.
  237. </p>
  238. <div class="smallexample">
  239. <pre class="smallexample">{
  240. int sum = 0;
  241. int ix;
  242. for (ix = 0; ix != 10000; ix++)
  243. sum += some_expression;
  244. }
  245. </pre></div>
  246. <p>Even though <code>sum</code> is accumulated in the loop, no use is made of
  247. that summation, so the accumulation can be removed.
  248. </p>
  249. </li><li> Making side effects happen in the same order as in some other compiler.
  250. <a name="index-side-effects_002c-order-of-evaluation"></a>
  251. <a name="index-order-of-evaluation_002c-side-effects"></a>
  252. <p>It is never safe to depend on the order of evaluation of side effects.
  253. For example, a function call like this may very well behave differently
  254. from one compiler to another:
  255. </p>
  256. <div class="smallexample">
  257. <pre class="smallexample">void func (int, int);
  258. int i = 2;
  259. func (i++, i++);
  260. </pre></div>
  261. <p>There is no guarantee (in either the C or the C++ standard language
  262. definitions) that the increments will be evaluated in any particular
  263. order. Either increment might happen first. <code>func</code> might get the
  264. arguments &lsquo;<samp>2, 3</samp>&rsquo;, or it might get &lsquo;<samp>3, 2</samp>&rsquo;, or even &lsquo;<samp>2, 2</samp>&rsquo;.
  265. </p>
  266. </li><li> Making certain warnings into errors by default.
  267. <p>Some ISO C testsuites report failure when the compiler does not produce
  268. an error message for a certain program.
  269. </p>
  270. <a name="index-pedantic_002derrors-2"></a>
  271. <p>ISO C requires a &ldquo;diagnostic&rdquo; message for certain kinds of invalid
  272. programs, but a warning is defined by GCC to count as a diagnostic. If
  273. GCC produces a warning but not an error, that is correct ISO C support.
  274. If testsuites call this &ldquo;failure&rdquo;, they should be run with the GCC
  275. option <samp>-pedantic-errors</samp>, which will turn these warnings into
  276. errors.
  277. </p>
  278. </li></ul>
  279. <hr>
  280. <div class="header">
  281. <p>
  282. Next: <a href="Warnings-and-Errors.html#Warnings-and-Errors" accesskey="n" rel="next">Warnings and Errors</a>, Previous: <a href="C_002b_002b-Misunderstandings.html#C_002b_002b-Misunderstandings" accesskey="p" rel="prev">C++ Misunderstandings</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>
  283. </div>
  284. </body>
  285. </html>