Skip to content

Since C23 bool is keyword #1576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Roman3349 opened this issue Feb 17, 2025 · 10 comments · May be fixed by #1597
Open

Since C23 bool is keyword #1576

Roman3349 opened this issue Feb 17, 2025 · 10 comments · May be fixed by #1597
Milestone

Comments

@Roman3349
Copy link
Contributor

Describe the bug
Since C23 bool is keyword, so typedef unsigned int bool; causes compilation error. This is used in

typedef unsigned int bool;

To Reproduce

  1. Compile the library with GCC15

Expected behavior
Successful compilation.

Log files

[...]
[ 10%] Building C object src/CMakeFiles/common_ssl_obj_static.dir/Tree.c.o
cd /build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu/src && /usr/bin/cc -DOPENSSL=1 -DPAHO_MQTT_STATIC=1 -D_GNU_SOURCE  -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/paho.mqtt.c-1.3.14=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC   -fvisibility=hidden -MD -MT src/CMakeFiles/common_ssl_obj_static.dir/Tree.c.o -MF CMakeFiles/common_ssl_obj_static.dir/Tree.c.o.d -o CMakeFiles/common_ssl_obj_static.dir/Tree.c.o -c /build/reproducible-path/paho.mqtt.c-1.3.14/src/Tree.c
[ 10%] Building C object src/CMakeFiles/common_ssl_obj_static.dir/Socket.c.o
cd /build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu/src && /usr/bin/cc -DOPENSSL=1 -DPAHO_MQTT_STATIC=1 -D_GNU_SOURCE  -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/paho.mqtt.c-1.3.14=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC   -fvisibility=hidden -MD -MT src/CMakeFiles/common_ssl_obj_static.dir/Socket.c.o -MF CMakeFiles/common_ssl_obj_static.dir/Socket.c.o.d -o CMakeFiles/common_ssl_obj_static.dir/Socket.c.o -c /build/reproducible-path/paho.mqtt.c-1.3.14/src/Socket.c
In file included from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTProtocolClient.h:25,
                 from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTProtocolClient.c:35:
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: error: ‘bool’ cannot be defined via ‘typedef’
   31 | typedef unsigned int bool;
      |                      ^~~~
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:1: warning: useless type name in empty declaration
   31 | typedef unsigned int bool;
      | ^~~~~~~
[ 11%] Building C object src/CMakeFiles/common_ssl_obj_static.dir/Log.c.o
cd /build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu/src && /usr/bin/cc -DOPENSSL=1 -DPAHO_MQTT_STATIC=1 -D_GNU_SOURCE  -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/paho.mqtt.c-1.3.14=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC   -fvisibility=hidden -MD -MT src/CMakeFiles/common_ssl_obj_static.dir/Log.c.o -MF CMakeFiles/common_ssl_obj_static.dir/Log.c.o.d -o CMakeFiles/common_ssl_obj_static.dir/Log.c.o -c /build/reproducible-path/paho.mqtt.c-1.3.14/src/Log.c
make[3]: *** [src/CMakeFiles/common_ssl_obj_static.dir/build.make:96: src/CMakeFiles/common_ssl_obj_static.dir/MQTTProtocolClient.c.o] Error 1
make[3]: *** Waiting for unfinished jobs....
[ 11%] Building C object src/CMakeFiles/common_ssl_obj.dir/Clients.c.o
cd /build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu/src && /usr/bin/cc -DOPENSSL=1 -DPAHO_MQTT_EXPORTS=1 -D_GNU_SOURCE  -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/paho.mqtt.c-1.3.14=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC   -fvisibility=hidden -MD -MT src/CMakeFiles/common_ssl_obj.dir/Clients.c.o -MF CMakeFiles/common_ssl_obj.dir/Clients.c.o.d -o CMakeFiles/common_ssl_obj.dir/Clients.c.o -c /build/reproducible-path/paho.mqtt.c-1.3.14/src/Clients.c
In file included from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTProtocolClient.h:25,
                 from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTProtocolClient.c:35:
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: error: ‘bool’ cannot be defined via ‘typedef’
   31 | typedef unsigned int bool;
      |                      ^~~~
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:1: warning: useless type name in empty declaration
   31 | typedef unsigned int bool;
      | ^~~~~~~
In file included from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.c:28:
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: error: ‘bool’ cannot be defined via ‘typedef’
   31 | typedef unsigned int bool;
      |                      ^~~~
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:1: warning: useless type name in empty declaration
   31 | typedef unsigned int bool;
      | ^~~~~~~
[ 12%] Building C object src/CMakeFiles/common_ssl_obj.dir/utf-8.c.o
cd /build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu/src && /usr/bin/cc -DOPENSSL=1 -DPAHO_MQTT_EXPORTS=1 -D_GNU_SOURCE  -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/paho.mqtt.c-1.3.14=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC   -fvisibility=hidden -MD -MT src/CMakeFiles/common_ssl_obj.dir/utf-8.c.o -MF CMakeFiles/common_ssl_obj.dir/utf-8.c.o.d -o CMakeFiles/common_ssl_obj.dir/utf-8.c.o -c /build/reproducible-path/paho.mqtt.c-1.3.14/src/utf-8.c
make[3]: *** [src/CMakeFiles/common_ssl_obj.dir/build.make:96: src/CMakeFiles/common_ssl_obj.dir/MQTTProtocolClient.c.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [src/CMakeFiles/common_ssl_obj_static.dir/build.make:138: src/CMakeFiles/common_ssl_obj_static.dir/MQTTPacket.c.o] Error 1
In file included from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacketOut.h:23,
                 from /build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacketOut.c:30:
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: error: ‘bool’ cannot be defined via ‘typedef’
   31 | typedef unsigned int bool;
      |                      ^~~~
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:1: warning: useless type name in empty declaration
   31 | typedef unsigned int bool;
      | ^~~~~~~
make[3]: *** [src/CMakeFiles/common_ssl_obj_static.dir/build.make:152: src/CMakeFiles/common_ssl_obj_static.dir/MQTTPacketOut.c.o] Error 1
In file included from /build/reproducible-path/paho.mqtt.c-1.3.14/src/Log.c:27:
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: error: ‘bool’ cannot be defined via ‘typedef’
   31 | typedef unsigned int bool;
      |                      ^~~~
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:22: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
/build/reproducible-path/paho.mqtt.c-1.3.14/src/MQTTPacket.h:31:1: warning: useless type name in empty declaration
   31 | typedef unsigned int bool;
      | ^~~~~~~
make[3]: *** [src/CMakeFiles/common_ssl_obj_static.dir/build.make:208: src/CMakeFiles/common_ssl_obj_static.dir/Log.c.o] Error 1
make[3]: Leaving directory '/build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:454: src/CMakeFiles/common_ssl_obj.dir/all] Error 2
make[3]: Leaving directory '/build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:550: src/CMakeFiles/common_ssl_obj_static.dir/all] Error 2
make[2]: Leaving directory '/build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu'
make[1]: *** [Makefile:159: all] Error 2
make[1]: Leaving directory '/build/reproducible-path/paho.mqtt.c-1.3.14/obj-x86_64-linux-gnu'
dh_auto_build: error: cd obj-x86_64-linux-gnu && make -j8 "INSTALL=install --strip-program=true" VERBOSE=1 returned exit code 2
make: *** [debian/rules:10: binary] Error 25

Environment (please complete the following information):

  • OS: Debian experimental
  • Version 1.3.14

Additional context
Debian package downstream bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1097539

@icraggs icraggs added this to the 1.3.15 milestone Feb 20, 2025
@gerum100
Copy link

gerum100 commented May 5, 2025

The simplest possible fix for the problem is to specify the used C standard instead of using the compiler default by doing set(CMAKE_C_STANDARD 90) somewhere in the CMakeLists.txt

@fpagliughi
Copy link
Contributor

fpagliughi commented May 6, 2025

@icraggs , I can take this one. Is there a specific version to target? I'm thinking C99?

@icraggs
Copy link
Contributor

icraggs commented May 8, 2025

@fpagliughi thanks. Yes, C99. I saw that Curl goes for C89 -- I presume you weren't thinking that far back!

@icraggs
Copy link
Contributor

icraggs commented May 8, 2025

@gerum100 not everyone builds with CMake. I think a source code fix would result in less maintenance in the future.

@fpagliughi
Copy link
Contributor

C23 adds a number of keywords, and this time they're using some common ones: bool, true, false, etc.
So this is going to break a lot of code; not just us.

The quick fix is just tell the compiler to use a specific standard (i.e. C99). I have no problem with this because it's what we've been doing with C++ for years. Originally this was to push the compiler to use a newer standard that the default, like supporting C++11 years back when the compilers were still defaulting to C++98/03. But now it's often used to hold the compiler back as changes are coming at a faster pace; like keeping to C++17 in the face of C++20/23 changes.

Anyway, this does cause problems with the headers. If someone wanted to bring C99 headers into an app that wants to use C23, then there are problems.

So I think we should release a quick fix for the CMake build ASAP, with notes in the README, saying this can only be built as C99. And then within the next few months get it compatible with C23 using some conditional compilation to only #define the new keywords if we're on an older standard than C23.

@vbaderks
Copy link

vbaderks commented May 8, 2025

@fpagliughi Why not rename typedef unsigned int bool; in for example typedef unsigned int mttq_bool?
No functional change and it should be relative safe.

@icraggs
Copy link
Contributor

icraggs commented May 13, 2025

@fpagliughi I think it's the right thing to do to set the C level in the CMake config, along with documenting it.

It seems that the impact to us here is very limited - only MQTTPacket.h uses the bool definition. I'm happy changing these few uses to unsigned int, or the definition name to boolean, or similar. I just tried this, and that's all I had to do (at least with clang that I used).

fpagliughi added a commit to fpagliughi/paho.mqtt.c that referenced this issue May 14, 2025
@fpagliughi
Copy link
Contributor

fpagliughi commented May 14, 2025

EDIT: I initially thought we had to change the code because the violation was in a header file. But it seems that header is private to the library and not exposed to the applications, so changing the CMake build would suffice to fix this. But, as @icraggs pointed out, the problem is isolated and pretty trivial to fix by updating the source code, so I changed my mind and now recommend fixing the sources to make the code compliant with C23.

Thinking about it, changing the CMake files won't do much because the typedef is exposed in a header file. So an app that uses a C23 compiler would still hit the problem by including the headers.

@icraggs , you're correct. The only real solution is to take out the typedef from MQTTPacket.h or change it to a name that isn't a keyword. I thought to use bit.

@fpagliughi fpagliughi linked a pull request May 14, 2025 that will close this issue
@destroyedlolo
Copy link

Should include <stdbool.h> be a solution ?

@fpagliughi
Copy link
Contributor

fpagliughi commented May 21, 2025

I don't think so in this specific situation. In the code it was used in only one internal file to indicate single-bit fields in the structs that formed the wire packets for transfer. Thus it was for a specific one-bit representation of a bool within an integer, not a generic boolean. So the bit representation is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants