Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

Boolean macros definitions

$
0
0

Hello everybody,

I am back to an issue I see it was touched here and there, but I would like to come to a "standard" solution for it.

I am using LabWindows/CVI 2017, so it has clang 3.3, with most of the clang 3.3 headers available.
I told the IDE to include the path to the clang 3.3 include files in its directories for compiling, plus I AM using the clang compiler.

I want to use bool, false and true ANSI C99 macros as per the C99 documentation and the clang 3.3 documentation.

I therefore #include <stdbool.h>

Compile error: use of undeclared identifier 'false'
Where the problem may come from? I opened stdbool.h and found:

 

#ifndef __STDBOOL_H
#define __STDBOOL_H

/* Don't define bool, true, and false in C++, except as a GNU extension. */
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool, bool, false, true as a GNU extension. */
#define _Bool bool
#define bool  bool
#define false false
#define true  true
#endif

#define __bool_true_false_are_defined 1

#endif /* __STDBOOL_H */

 

This is very straightforward code, so I came up with a very silly idea: in my header file (.h) I catch-up the definition of these macros before and after the stdbool.h inclusion:

 

#ifdef __STDBOOL_H
    #error __STDBOOL_H defined already!
#else
    #error __STDBOOL_H NOT defined!
#endif
#ifdef __cplusplus
    #error __cplusplus defined! Graph.h will undefine it so that stdbool.h can define it again
    #undef __cplusplus
#else
    #error __cplusplus NOT defined!
#endif
#ifndef bool
    #error bool NOT defined!
#else
    #error bool defined already!
#endif
#ifndef false
    #error false NOT defined!
#else
    #error false defined already!
#endif
#ifndef true
    #error true NOT defined!
#else
    #error true defined already!
#endif
#ifdef __bool_true_false_are_defined
    #error __bool_true_false_are_defined ARE defined already!
#else
    #error __bool_true_false_are_defined NOT defined!
#endif

#include <stdbool.h>

#ifndef bool
    #error bool NOT defined!
#else
    #error bool defined already!
#endif
#ifndef false
    #error false NOT defined!
#else
    #error false defined already!
#endif
#ifndef true
    #error true NOT defined!
#else
    #error true defined already!
#endif
#ifdef __bool_true_false_are_defined
    #error __bool_true_false_are_defined ARE defined already!
#else
    #error __bool_true_false_are_defined NOT defined!
#endif

 

 When I build the project, I get this from the code file (.c) compilation:

 

error: #error __STDBOOL_H NOT defined!

error: #error __cplusplus NOT defined!

error: #error bool NOT defined!

error: #error false NOT defined!

error: #error true NOT defined!

error: #error __bool_true_false_are_defined NOT defined!

error: #error bool defined already!

error: #error false defined already!

error: #error true defined already!

error: #error __bool_true_false_are_defined ARE defined already!

error: use of undeclared identifier 'false'

 

Can anybody help me, please?


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>