Hi!

On Tue, Jan 07, 2020 at 03:15:05PM +0000, Wilco Dijkstra wrote:
> --- 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>

IMHO we should mention also the common attribute, in some cases the common
behavior is intentional decision and there is no problem supporting it,
just the code should mark it explicitly.

Ok for wwwdocs?

diff --git a/htdocs/gcc-10/porting_to.html b/htdocs/gcc-10/porting_to.html
index 980d3af1..c5d7eb82 100644
--- a/htdocs/gcc-10/porting_to.html
+++ b/htdocs/gcc-10/porting_to.html
@@ -41,7 +41,12 @@ and provide solutions. Let us know if you have suggestions 
for improvements!
   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>.
+  If tentative definitions of particular variable or variables need to be
+  placed in a common block, <code>__attribute__((__common__))</code> can be
+  used to force that behavior for those even in code compiled without
+  <code>-fcommon</code>.
+  As a workaround, legacy C code where all tentative definitions should
+  be placed into a common block can be compiled with <code>-fcommon</code>.
 </p>
   <pre><code>
       int x;  // tentative definition - avoid in header files


        Jakub

Reply via email to