In a project I am interfacing between c++ and a c library that uses stdbool.h defined as such.
#ifndef _STDBOOL_H
#define _STDBOOL_H
/* C99 Boolean types for compilers without C99 support */
/* */
#if !defined(__cplusplus)
#if !defined(__GNUC__)
/* _Bool builtin type is included in GCC */
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
#endif
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#endif
Some structures have bool
members. So if I have one of these structures defined as local variables within a c++ function and pass it to a c function the sizes are inconsistent between c++ and c as bool is one bye in c++ and 4 in c.
Does anyone have any advice to how to overcome this without resorting to my current solution which is
//#define bool _Bool
#define bool unsigned char
Which is against the C99 standard for stdbool.h