PowerBroker2 / SafeString

This SafeString library is designed for beginners to be a safe, robust and debuggable replacement for string processing in Arduino. Note, this is NOT my work, I am simply hosting it for easy access. The original code belongs to Forward Computing and Control Pty. Ltd.
https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html
38 stars 12 forks source link

Fix redefinition of "bool" type in library header #74

Closed legerch closed 5 months ago

legerch commented 5 months ago

When including "Safestring.h" library for an ARDUINO_ARCH_SAM, boolean type is redefined to an integer. This will pollute our sketch since this redefinition is inside the header.
Fix it by using a custom boolean type name for this library

drmpf commented 5 months ago

In SafeString.h try replacing

#if defined(ARDUINO_ARCH_SAM)
#define bool int
#endif

#ifdef __cplusplus

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

with

#ifdef __cplusplus

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

That change seems to work for SAM boards

legerch commented 5 months ago

In SafeString.h try replacing

#if defined(ARDUINO_ARCH_SAM)
#define bool int
#endif

#ifdef __cplusplus

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

with

#ifdef __cplusplus

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

That change seems to work for SAM boards

I can confirm that this properly work, bool is a proper boolean type with those changes.
Do you want me to update this PR with this method instead ?

drmpf commented 5 months ago

No thats fine, I will do a new release with this fix and update the PlatformIO zips as well. Thanks for finding this.

legerch commented 5 months ago

Noted, thank you for maintaining this library :)

drmpf commented 5 months ago

fixed in V4.1.33