xref: /btstack/src/btstack_bool.h (revision 9eadad2068cc64aed0b2e109af6a00a371bb8c11)
11c4468cfSMatthias Ringwald /*
21c4468cfSMatthias Ringwald  * Copyright (C) 2019 BlueKitchen GmbH
31c4468cfSMatthias Ringwald  *
41c4468cfSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
51c4468cfSMatthias Ringwald  * modification, are permitted provided that the following conditions
61c4468cfSMatthias Ringwald  * are met:
71c4468cfSMatthias Ringwald  *
81c4468cfSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
91c4468cfSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
101c4468cfSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
111c4468cfSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
121c4468cfSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
131c4468cfSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
141c4468cfSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
151c4468cfSMatthias Ringwald  *    from this software without specific prior written permission.
161c4468cfSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
171c4468cfSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
181c4468cfSMatthias Ringwald  *    monetary gain.
191c4468cfSMatthias Ringwald  *
201c4468cfSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
211c4468cfSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221c4468cfSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
251c4468cfSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261c4468cfSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
271c4468cfSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
281c4468cfSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
291c4468cfSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
301c4468cfSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311c4468cfSMatthias Ringwald  * SUCH DAMAGE.
321c4468cfSMatthias Ringwald  *
331c4468cfSMatthias Ringwald  * Please inquire about commercial licensing options at
341c4468cfSMatthias Ringwald  * [email protected]
351c4468cfSMatthias Ringwald  *
361c4468cfSMatthias Ringwald  */
371c4468cfSMatthias Ringwald 
381c4468cfSMatthias Ringwald /*
391c4468cfSMatthias Ringwald  * btstack_bool.h
401c4468cfSMatthias Ringwald  *
411c4468cfSMatthias Ringwald  * Provide bool type */
421c4468cfSMatthias Ringwald 
431c4468cfSMatthias Ringwald #ifndef BTSTACK_BOOL_H
441c4468cfSMatthias Ringwald #define BTSTACK_BOOL_H
451c4468cfSMatthias Ringwald 
461c4468cfSMatthias Ringwald #if !defined(__cplusplus)
471c4468cfSMatthias Ringwald 
481c4468cfSMatthias Ringwald //
491c4468cfSMatthias Ringwald // Check for C99
501c4468cfSMatthias Ringwald // see: https://sourceforge.net/p/predef/wiki/Standards/
511c4468cfSMatthias Ringwald //
521c4468cfSMatthias Ringwald #if defined(__STDC__)
531c4468cfSMatthias Ringwald #   if defined(__STDC_VERSION__)
541c4468cfSMatthias Ringwald #     if (__STDC_VERSION__ >= 199901L)
551c4468cfSMatthias Ringwald #       define PREDEF_STANDARD_C_1999
561c4468cfSMatthias Ringwald #     endif
571c4468cfSMatthias Ringwald #  endif
581c4468cfSMatthias Ringwald #endif /* __STDC__ */
591c4468cfSMatthias Ringwald 
60*9eadad20SMatthias Ringwald // Detecting C99 in Visual Studio requires to disable Microsoft Extensions (/Za) which causes other issues
61*9eadad20SMatthias Ringwald // Workaround: if MSC, assume stdbool.h exists, which is true for Visual Studio 2022
62*9eadad20SMatthias Ringwald #ifdef _MSC_VER
63*9eadad20SMatthias Ringwald #define PREDEF_STANDARD_C_1999
64*9eadad20SMatthias Ringwald #endif
65*9eadad20SMatthias Ringwald 
661c4468cfSMatthias Ringwald // define boolean type - required for MISRA-C 2012 Essential Type System
671c4468cfSMatthias Ringwald #ifdef PREDEF_STANDARD_C_1999
681c4468cfSMatthias Ringwald 
691c4468cfSMatthias Ringwald // use <stdbool.h> if C99 or higher
701c4468cfSMatthias Ringwald #   include <stdbool.h>
711c4468cfSMatthias Ringwald 
721c4468cfSMatthias Ringwald #else /* PREDEF_STANDARD_C_1999 */
731c4468cfSMatthias Ringwald 
74a2c1e37eSMatthias Ringwald // backport for pre-c99 compilers or incorrect detection
75a2c1e37eSMatthias Ringwald #ifndef bool
761c4468cfSMatthias Ringwald #define bool unsigned char
77a2c1e37eSMatthias Ringwald #endif
78a2c1e37eSMatthias Ringwald #ifndef false
791c4468cfSMatthias Ringwald #define false 0
80a2c1e37eSMatthias Ringwald #endif
81a2c1e37eSMatthias Ringwald #ifndef true
821c4468cfSMatthias Ringwald #define true 1
83a2c1e37eSMatthias Ringwald #endif
841c4468cfSMatthias Ringwald 
851c4468cfSMatthias Ringwald #endif /* PREDEF_STANDARD_C_1999 */
861c4468cfSMatthias Ringwald 
871c4468cfSMatthias Ringwald #endif /* __cplusplus */
881c4468cfSMatthias Ringwald 
891c4468cfSMatthias Ringwald #endif /* BTSTACK_BOOL_H */
90