diff mbox series

wwwdocs: gcc-15: start adding notes on C23

Message ID 20241209194442.3154998-1-dmalcolm@redhat.com
State New
Headers show
Series wwwdocs: gcc-15: start adding notes on C23 | expand

Commit Message

David Malcolm Dec. 9, 2024, 7:44 p.m. UTC
How does this look?

Thanks
Dave

---
 htdocs/gcc-15/changes.html    | 12 ++++++++++++
 htdocs/gcc-15/porting_to.html | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

Comments

Jakub Jelinek Dec. 9, 2024, 7:58 p.m. UTC | #1
On Mon, Dec 09, 2024 at 02:44:42PM -0500, David Malcolm wrote:
> +C23 brings the following changes:
> +
> +<h4 id="c23-empty-fn-prototypes-become-void">Function prototypes with empty params change from implicit <code>int</code> to <code>void</code></h4>
> +
> +<p> In C23 <code>()</code> in a function declaration means the same as <code>(void)</code>, whereas previously it implicitly declared the function to take an <code>int</code> parameter.</p>

This isn't true.  void foo (); used to be an unprototyped function,
one could pass any arguments to it (of course without invoking UB
only if it actually matched the arguments passed to it).
So, with
void foo ();
int bar ();
one can
  foo (1, 2.0, 3L, bar (2));
if the definitions were
void foo (int a, double b, long c, int d) {
//...
}
int bar (int e) {
//...
}
or K&R-ish
void foo (f, g, h, i)
  int f;
  double g;
  long h;
  int i;
{
/* ... */
}
void bar (j)
  int j;
{
/* ... */
}

Implicit int was about completely undeclared functions in K&R/C89,
those were assumed to return int.  But we already error on those by
default in C99 and later modes, so no need to describe it again.

	Jakub
diff mbox series

Patch

diff --git a/htdocs/gcc-15/changes.html b/htdocs/gcc-15/changes.html
index 23866bde..94731f55 100644
--- a/htdocs/gcc-15/changes.html
+++ b/htdocs/gcc-15/changes.html
@@ -96,6 +96,18 @@  a work-in-progress.</p>
 	    <code>musttail</code> statement attribute</a> was added to enforce tail calls.</li>
 </ul>
 
+<h3 id="c">C</h3>
+<ul>
+  <li>GCC 15 changes the default language version for C compilation from
+    <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=gnu17</a>
+    to
+    <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=gnu23</a>.
+    If your code relies on older versions of the C standard, you will need to
+    either add
+    <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=</a>
+    to your build flags, or port your code; see <a href="porting_to.html#c23">the porting notes</a>.
+</ul>
+
 <h3 id="cxx">C++</h3>
 
 <ul>
diff --git a/htdocs/gcc-15/porting_to.html b/htdocs/gcc-15/porting_to.html
index 702cf507..2c9dce68 100644
--- a/htdocs/gcc-15/porting_to.html
+++ b/htdocs/gcc-15/porting_to.html
@@ -27,7 +27,39 @@  and provide solutions. Let us know if you have suggestions for improvements!
 <p>Note: GCC 15 has not been released yet, so this document is
 a work-in-progress.</p>
 
-<!-- <h2 id="c">C language issues</h2> -->
+<h2 id="c">C language issues</h2>
+
+<h3 id="c23">C23 by default</h3>
+<!-- change of default was in commit 55e3bd376b2214e200fa76d12b67ff259b06c212 -->
+
+GCC 15 changes the default language version for C compilation from
+<a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=gnu17</a>
+to
+<a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=gnu23</a>.
+
+If your code relies on older versions of the C standard, you will need to
+either add <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=</a>
+to your build flags, or port your code.
+
+C23 brings the following changes:
+
+<h4 id="c23-empty-fn-prototypes-become-void">Function prototypes with empty params change from implicit <code>int</code> to <code>void</code></h4>
+
+<p> In C23 <code>()</code> in a function declaration means the same as <code>(void)</code>, whereas previously it implicitly declared the function to take an <code>int</code> parameter.</p>
+
+<p>Hence
+
+<code>extern int foo();</code>
+
+now means
+
+<code>extern int foo(void);</code>
+
+rather than
+
+<code>extern int foo(int);</code>
+
+<p>Code relying on an implicit <code>int</code> param declaration can be fixed for C23 by adding an explicit <code>int</code> to the function prototype, or you can use <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1">-std=</a> to select an earlier version of the C standard.</p>
 
 <h2 id="cxx">C++ language issues</h2>