[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fun with c23
From: |
Jeffrey Cliff |
Subject: |
fun with c23 |
Date: |
Thu, 8 Aug 2024 23:36:18 -0600 |
tl;dr c23 changes break compilation. 2 small patches
[Firstly: apologize if this went to the wrong list - according to my
(terrible) email provider it didn't go out. Hopefully this is the
correct list]
Looks like at least two kinds of changes to C coming with C23 (ie
compiling with -std=gnu2x / gnu23), both involving changes to the
arguments of functions and how explicit you have to be about them.
And when I compile with -std=gnu23 (ie compile to the C23 standard) it
means 2 compilation problems result:
1)
* whereas before it was OK to define strerror without being explicit
about its argument,
it seems to depend on an int being provided as an argument
/usr/include/string.h
419 | extern char *strerror (int __errnum) __THROW;
| ^~~~~~~~
(man 3 strerror seems to agree: it should have an argument
char *strerror(int errnum);
so when ./system.h attempts to define it
#ifndef HAVE_DECL_STRERROR
extern char *strerror ();
#endif
for some reason two things go wrong
i) gcc doesn't seem to define HAVE_DECL_STRERROR leading to ( ???
google is telling me nothing about how this is supposed to be defined
)
ii) an attempt made to define it externally with the wrong definition
changing it to
extern char *strerror (int);
or better yet
extern char *strerror (int) __THROW;
makes it at least compile past that point.
then the real fun starts
2) because there's a *whole bunch* of functions declared as VFunctions
with various kinds of arguments (for example cmd in echo-area.c and
m-x.c 's command-func)
Now the good news is: c23 provides a way to change the VFunction
definition to not care about the argument abuse so frequently employed
: the '...' type. (Which is also fun to search for information on -
https://thephd.dev/c23-is-coming-here-is-what-is-on-the-menu guess the
technical term is "variadic parameter lists" ).
OK now for the changes to fix it.
one thing is to just #ifdef guard the change needed to get it to
compile with c23 on both info/info.h and ./system.h
# diff -Naur texinfo-7.1/system.h texinfo-7.1-compiles/system.h
--- texinfo-7.1/system.h 2023-08-15 06:00:01.000000000 -0600
+++ texinfo-7.1-compiles/system.h 2024-08-08 23:20:03.613636469 -0600
@@ -66,7 +66,12 @@
#endif
#ifndef HAVE_DECL_STRERROR
-extern char *strerror ();
+#if __STDC_VERSION__ < 202311L
+extern char *strerror () ;
+#endif
+#if __STDC_VERSION__ >= 202311L
+extern char *strerror (int) __THROW;
+#endif
#endif
#include <limits.h>
# diff -Naur texinfo-7.1/info/info.h texinfo-7.1-compiles/info/info.h
--- texinfo-7.1/info/info.h 2023-08-14 12:53:20.000000000 -0600
+++ texinfo-7.1-compiles/info/info.h 2024-08-08 23:22:44.454624287 -0600
@@ -25,7 +25,13 @@
/* Some of our other include files use these. */
typedef int Function ();
+#if __STDC_VERSION__ < 202311L
typedef void VFunction ();
+#endif
+#if __STDC_VERSION__ >= 202311L
+typedef void VFunction (...);
+#endif
+
typedef char *CFunction ();
#include "string.h"
or do so just with the info.h one and just make the changes to the
extern definition in system.h (that works for me (TM))
Either way that gets it compiling on my end (with CFLAGS+="
-std=gnu2x" and gnu23).
Jeff Cliff
--
------------------------------------------------------------------------------------------------
End the campaign to Cancel Richard Stallman - go to stallmansupport.org !
------------------------------------------------------------------------------------------------
- fun with c23,
Jeffrey Cliff <=