01-08-2018 06:53 AM
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?
Solved! Go to Solution.
01-08-2018 07:33 AM
I can tell you that CVI 2017 compiles fine when using bool...
I also use #include <stdbool.h> but without any errors, so I would assume that you miss something in your configuration, build options...
( I did not study your code example )
@MarinoMaiorino wrote:
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'
01-08-2018 08:00 AM
Thank you Wolfgang,
I set up my build options just like yours and of course the warnings multiplied (but that is good: they are there for the sake of code safety), yet the false macro is still undeclared.
😕
01-08-2018 08:10 AM
What confused me in your original message was your statement:
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 don't recall that I had to add a path (but maybe it's too long ago that I have set it up), and you don't have to do anything special to use clang since it is the default:
01-08-2018 08:36 AM
Ooookaaayyy...
I set up the build options as you have them. The difference was in the maximum number of compile errors, 20 instead of 100, and Show Build Output window when build starts.
The problem is still there: 'false' identifier undeclared.
By the way, taking the clang\3.3 path out of the extra paths, solved another problem I had with intmax_t and uintmax_t definitions so, thank you for that!
01-09-2018 02:46 AM
Aaaaand... SOLVED!
The thing is (rather worrisomely) that I can't figure out why it is like this, but this is how I made it work.
Triggered by some other messages I found here and there, and by the results of the test I described in the first post, I thought that the order of the includes could play a role.
I know what you will say: "Of course, it does!", but up to the present day I followed what I found out to be a "reasonable" (at least, it looked like that to me) scheme, where I included the library header files first (those within <>) and then "my" libraries (those within "").
The logic behind that was that all ""-files need <>-files to work, don't they?
But as the inclusion order is at stakes, then I want the boolean definitions as close as possible to the code using them, so I simply included <stdbool.h> as the last one, even after my own "" libraries. In the end, stdbool.h is a very simple file with only a few typedefs and defines, so it shouldn't really matter where you put it (well, apparently that's not the case).
BOOM! Software built with no "'false' undeclared error"!
What a nice way to start a working day, I wish it could go on like this!
Now, what bugs me is: it should not matter where stdbool.h is so, where was the problem coming from? If it was my code (highly probable, in its early development stage), I have some serious issue I can't recall (no good at all!), but that I can eventually tame; if it was something odd in CVI libraries or whatever... I wish nothing will bite me unexpectedly.
Cheers, and thank you Wolfgang for your prompt replies!