[wwwdocs] gcc-15/porting_to: add section on new C23 keywords

Message ID 20250115172038.1920843-1-dmalcolm@redhat.com
State New
Headers
Series [wwwdocs] gcc-15/porting_to: add section on new C23 keywords |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

David Malcolm Jan. 15, 2025, 5:20 p.m. UTC
  OK to push?

---
 htdocs/gcc-15/porting_to.html | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
  

Comments

Joseph Myers Jan. 15, 2025, 6:25 p.m. UTC | #1
On Wed, 15 Jan 2025, David Malcolm wrote:

> +<p>
> +  In C99 and later you can use <code>#include &lt;stdbool.h&gt;</code>
> +  which provides a definition of <code>bool</code> compatible with C23.
> +</p>
> +  Note that the <code>bool</code> type is <b>not</b> the same
> +  as <code>int</code> at ABI level, and so care may be needed porting
> +  declarations that appear at an ABI boundary (or serialized to the
> +  filesystem.
> +</p>

OK, though this last paragraph should probably have an opening <p>, and as 
discussed on IRC it might make sense to mention that C99/C23 bool can only 
store values 0 and 1.  Maybe also mention that <stdbool.h> provides all of 
bool, true and false (not just bool).
  
David Malcolm Jan. 15, 2025, 7:19 p.m. UTC | #2
On Wed, 2025-01-15 at 18:25 +0000, Joseph Myers wrote:
> On Wed, 15 Jan 2025, David Malcolm wrote:
> 
> > +<p>
> > +  In C99 and later you can use <code>#include
> > &lt;stdbool.h&gt;</code>
> > +  which provides a definition of <code>bool</code> compatible with
> > C23.
> > +</p>
> > +  Note that the <code>bool</code> type is <b>not</b> the same
> > +  as <code>int</code> at ABI level, and so care may be needed
> > porting
> > +  declarations that appear at an ABI boundary (or serialized to
> > the
> > +  filesystem.
> > +</p>
> 
> OK, though this last paragraph should probably have an opening <p>,
> and as 
> discussed on IRC it might make sense to mention that C99/C23 bool can
> only 
> store values 0 and 1.  Maybe also mention that <stdbool.h> provides
> all of 
> bool, true and false (not just bool).

Thanks; I've pushed this version of the patch:

---
 htdocs/gcc-15/porting_to.html | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/htdocs/gcc-15/porting_to.html b/htdocs/gcc-
15/porting_to.html
index e6da6cd9..7344afa5 100644
--- a/htdocs/gcc-15/porting_to.html
+++ b/htdocs/gcc-15/porting_to.html
@@ -43,6 +43,36 @@ to your build flags, or port your code to C23.
 
 <!-- C23 brings the following changes: -->
 
+<h4 id="c23-new-keywords">New keywords</h4>
+<p>
+  C23 added various new keywords, including
+  <code>bool</code>, <code>true</code>, <code>false</code>,
+  <code>nullptr</code>, and <code>thread_local</code>.
+  Code that uses these for identifiers will need changing.
+  For example <code>typedef int bool;</code> will
+  <a href="https://godbolt.org/z/7W8fMT9zd">fail</a> with:
+</p>
+<pre><code>
+&lt;source&gt;:1:13: error: 'bool' cannot be defined via 'typedef'
+    1 | typedef int bool;
+      |             ^~~~
+&lt;source&gt;:1:13: note: 'bool' is a keyword with '-std=c23' onwards
+&lt;source&gt;:1:1: warning: useless type name in empty declaration
+    1 | typedef int bool;
+      | ^~~~~~~
+</code></pre>
+<p>
+  In C99 and later you can use <code>#include &lt;stdbool.h&gt;</code>
+  which provides definitions of <code>bool</code>, <code>true</code>,
+  and <code>false</code> compatible with C23.
+</p>
+<p>
+  Note that the <code>bool</code> type is <b>not</b> the same
+  as <code>int</code> at ABI level, and so care may be needed porting
+  declarations that appear at an ABI boundary (or serialized to the
+  filesystem).
+</p>
+
 <h2 id="cxx">C++ language issues</h2>
 
 <h3 id="header-dep-changes">Header dependency changes</h3>
  

Patch

diff --git a/htdocs/gcc-15/porting_to.html b/htdocs/gcc-15/porting_to.html
index 385fa141..53512250 100644
--- a/htdocs/gcc-15/porting_to.html
+++ b/htdocs/gcc-15/porting_to.html
@@ -94,6 +94,34 @@  In file included from &lt;source&gt;:1:
   to select an earlier version of the C standard.
 </p>
 
+<h4 id="c23-new-keywords">New keywords</h4>
+<p>
+  C23 added various new keywords, including
+  <code>bool</code>, <code>true</code>, <code>false</code>,
+  <code>nullptr</code>, and <code>thread_local</code>.
+  Code that uses these for identifiers will need changing.
+  For example <code>typedef int bool;</code> will
+  <a href="https://godbolt.org/z/7W8fMT9zd">fail</a> with:
+</p>
+<pre><code>
+&lt;source&gt;:1:13: error: 'bool' cannot be defined via 'typedef'
+    1 | typedef int bool;
+      |             ^~~~
+&lt;source&gt;:1:13: note: 'bool' is a keyword with '-std=c23' onwards
+&lt;source&gt;:1:1: warning: useless type name in empty declaration
+    1 | typedef int bool;
+      | ^~~~~~~
+</code></pre>
+<p>
+  In C99 and later you can use <code>#include &lt;stdbool.h&gt;</code>
+  which provides a definition of <code>bool</code> compatible with C23.
+</p>
+  Note that the <code>bool</code> type is <b>not</b> the same
+  as <code>int</code> at ABI level, and so care may be needed porting
+  declarations that appear at an ABI boundary (or serialized to the
+  filesystem.
+</p>
+
 <h2 id="cxx">C++ language issues</h2>
 
 <h3 id="header-dep-changes">Header dependency changes</h3>