tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: stdbool.h #define bool _Bool



On 31.07.2019 10:55, coypu%sdf.org@localhost wrote:
> hi folks,
> 
> while building an updated Mono, I came across a familiar issue:
> 
> icall.c:9175:35: error: ‘ICALL_SIG_TYPE__Bool’ undeclared here (not in a function); did you mean ‘ICALL_SIG_TYPE_bool’?
>  #define ICALL_SIG_TYPES_1(a)      ICALL_SIG_TYPE_ ## a,
> 
> 
> I've had this issue before with macros, but in this case, the macro is
> mandated by the C standard, so there's no escaping it.
> 
> A reduced version of it is:
> 
> #include <stdbool.h>
> 
> #define function(name, type) int name##_##type() { return 3; }
> #define useless_wrapper(name, type) function(name, type)
> 
> useless_wrapper(something, bool)
> 
> int main() {
> 	return something_bool();
> }
> 
> 
> -----
> 
> In this case, Mono doesn't include stdbool.h, it's side-loaded for us.
> I can avoid the issue with a hack #undef bool, but I'd like to see a
> future where Mono works unmodified on unmodified NetBSD, without the use
> of hacks.
> 
> I'm thinking of the following solution: avoid directly including
> stdbool.h in any regular userland headers, and having headers use
> _Bool as a type.
> 
> I needed to change net/if.h, net/route.h and sys/psref.h.
> 


In that case this definition of bool is mandated as a part of the C
specification.

It's a well established tradition to use a macro for it as it is
compatible with pre-C99 code and _Bool does not exist in C++ so it will
break the headers for at least C++ and pre-C99 build mode.

In the mono case, I recommend to rename in the code usage of bool with
boolean (optionally with uppercase).

Alternatively go for: #undef or #define __bool_true_false_are_defined.

> Thoughts?
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index