xref: /btstack/src/btstack_bool.h (revision a2c1e37ed40a346e8d340345fb9fcf390a4981fb)
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 
601c4468cfSMatthias Ringwald // define boolean type - required for MISRA-C 2012 Essential Type System
611c4468cfSMatthias Ringwald #ifdef PREDEF_STANDARD_C_1999
621c4468cfSMatthias Ringwald 
631c4468cfSMatthias Ringwald // use <stdbool.h> if C99 or higher
641c4468cfSMatthias Ringwald #   include <stdbool.h>
651c4468cfSMatthias Ringwald 
661c4468cfSMatthias Ringwald #else /* PREDEF_STANDARD_C_1999 */
671c4468cfSMatthias Ringwald 
68*a2c1e37eSMatthias Ringwald // backport for pre-c99 compilers or incorrect detection
69*a2c1e37eSMatthias Ringwald #ifndef bool
701c4468cfSMatthias Ringwald #define bool unsigned char
71*a2c1e37eSMatthias Ringwald #endif
72*a2c1e37eSMatthias Ringwald #ifndef false
731c4468cfSMatthias Ringwald #define false 0
74*a2c1e37eSMatthias Ringwald #endif
75*a2c1e37eSMatthias Ringwald #ifndef true
761c4468cfSMatthias Ringwald #define true 1
77*a2c1e37eSMatthias Ringwald #endif
781c4468cfSMatthias Ringwald 
791c4468cfSMatthias Ringwald #endif /* PREDEF_STANDARD_C_1999 */
801c4468cfSMatthias Ringwald 
811c4468cfSMatthias Ringwald #endif /* __cplusplus */
821c4468cfSMatthias Ringwald 
831c4468cfSMatthias Ringwald #endif /* BTSTACK_BOOL_H */
84