Unknown type name 'bool'

This message appears on the online editor when I add a Modbus master using ArduinoRS485 and ArduinoModbus (in a special version called "_S" for the online editor, since it detects conflicts between ArduinoIot and ArduinoModbus about "On" and "Off" definitions.) on a Portenta H7 with breakout board.

The full description is :

In file included from /home/builder/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/variants/PORTENTA_H7_M7/pinmode_arduino.h:30:0,
from /home/builder/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/cores/arduino/Arduino.h:26,
from /mnt/create-efs/webide/6b/09/6b0945c459af72e04d2dbdea10cd4771:i_diallo/libraries_v2/ArduinoModbus_S/src/libmodbus/modbus.c:22:
/home/builder/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/cores/arduino/api/Common.h:75:9: error: unknown type name 'bool'

typedef bool boolean;
^~~~

Error during build: exit status 1

By the way, not one of the booleans declared in the code uses "bool" as a declarant instead of "boolean".

Any ideas welcome !

I think that the 'bool' type is a C++ thing and may not be available in C code. Try including "stdbool.h"

The primary Arduino core header file Arduino.h has an #include directive for api/ArduinoAPI.h:
https://github.com/arduino/ArduinoCore-mbed/blob/2.6.1/cores/arduino/Arduino.h#L27

ArduinoAPI.h in turn has an #include directive for Common.h:
https://github.com/arduino/ArduinoCore-API/blob/1.2.0/api/ArduinoAPI.h#L50
Finally, Common.h typedefs the non-standard Processing-inherited boolean type to the standard bool type:
https://github.com/arduino/ArduinoCore-API/blob/1.2.0/api/Common.h#L75

That works fine with C++ code, but the modbus.c file is compiled as C, and something is missing for it to work with C:

In C99 the native type is actually called _Bool , while bool is a standard library macro defined in stdbool.h

This means that C code which has an #include directive for Arduino.h must first #include the file stdbool.h.

This was done in the latest release of the official ArduinoModbus library:

So I suspect that either the ArduinoModbus_S has not yet pulled in that change from the upstream library, or else you are using an outdated version of ArduinoModbus_S.

Thanks for your answer,
but I just had a look at both ArduinoModbus libraries (standard, and _S) I on the online IDE, and Stdbool.h is included in both just where the fix build mentionned, so I do not think this would be the problem.
I am currently working on using SimpleModbusMaster_DUE to work around the problem.
By the way, ArduinoModbus_S is the ArduinoModbus I had to modify to avoid some issues with a redefinition of "ON" and "OFF" somewhere in ArduinoIoT.
What ticks me off is this occurs only on the online IDE. Using 1.8.16 IDE offline, the same code loads like a breeze. And since I am running Windows, I cannot load ArduinoIoT programs (length of pathes known problem - should be solved in version 2).

So I stay a bit stuck at the moment.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.