Hi,

>On 1/6/20 7:10 AM, Jonathan Wakely wrote:
>> GCC now defaults to <code>-fno-common</code>.  As a result, global
>> variable accesses are more efficient on various targets.  In C, global
>> variables with multiple tentative definitions will result in linker
>> errors.
>
> This is better.  I'd also s/will/now/, since we're talking about the 
> present behavior of GCC 10, not some future behavior.

Thanks for the suggestions, I've reworded it as:

GCC now defaults to <code>-fno-common</code>.  As a result, global
variable accesses are more efficient on various targets.  In C, global
variables with multiple tentative definitions now result in linker errors.
With <code>-fcommon</code> such definitions are silently merged during
linking.

Also changed the anchor name (I think it was a copy/paste from another entry).
Here the updated version:


diff --git a/htdocs/gcc-10/changes.html b/htdocs/gcc-10/changes.html
index 
d6108269e977df2af29bd5c9149cc2136654ce05..45af7fa333cfff2155ff0346fe36855aa6ff940a
 100644
--- a/htdocs/gcc-10/changes.html
+++ b/htdocs/gcc-10/changes.html
@@ -140,6 +140,13 @@ a work-in-progress.</p>
     <li>In C2X mode, <code>-fno-fp-int-builtin-inexact</code> is
     enabled by default.</li>
   </ul></li>
+
+  <li>GCC now defaults to <code>-fno-common</code>.  As a result, global
+      variable accesses are more efficient on various targets.  In C, global
+      variables with multiple tentative definitions now result in linker 
errors.
+      With <code>-fcommon</code> such definitions are silently merged during
+      linking.
+  </li>
 </ul>
 
 <h3 id="cxx">C++</h3>
diff --git a/htdocs/gcc-10/porting_to.html b/htdocs/gcc-10/porting_to.html
index 
3256e8a35d00ce1352c169a1c6df6d8f120889ee..7d45a962d014fecece9bd52a13ca1799153672fe
 100644
--- a/htdocs/gcc-10/porting_to.html
+++ b/htdocs/gcc-10/porting_to.html
@@ -29,9 +29,25 @@ and provide solutions. Let us know if you have suggestions 
for improvements!
 <h2 id="cpp">Preprocessor issues</h2>
 -->
 
-<!--
 <h2 id="c">C language issues</h2>
--->
+
+<h3 id="common">Default to <code>-fno-common</code></h3>
+
+<p>
+  A common mistake in C is omitting <code>extern</code> when declaring a global
+  variable in a header file.  If the header is included by several files it
+  results in multiple definitions of the same variable.  In previous GCC
+  versions this error is ignored.  GCC 10 defaults to <code>-fno-common</code>,
+  which means a linker error will now be reported.
+  To fix this, use <code>extern</code> in header files when declaring global
+  variables, and ensure each global is defined in exactly one C file.
+  As a workaround, legacy C code can be compiled with <code>-fcommon</code>.
+</p>
+  <pre><code>
+      int x;  // tentative definition - avoid in header files
+
+      extern int y;  // correct declaration in a header file
+  </code></pre>
 
 <h2 id="fortran">Fortran language issues</h2>
 

Reply via email to