I have a double type bool so have added to a header:
typedef double bool;
extern bool true;
extern bool false;
with:
bool true = 1.0;
bool false = 0.0;
in the corresponding C file.
However I now have the errors multiple definition of true, and the same for false, pointing to the first line of the first function in the C file. the error that says ‘previous declaration was here’ points to the same line… it doesnt make any difference which function is placed first in the file it always points to it.
My header files, though included via a common header file, do have include guards so I hopefully shouldn’t have multiple declaration of true and false there.
I have changed the typedef to tBool with vars tTrue and tFalse, which solves the problem, but I don’t get why it occurred in the first place? As there are still some bool types using true and false in the code it seems like the compiler may have a definition for true and false as ints already… though I didn’t think C did this
Im using dev-c++ 4.9.9.2 IDE that uses mingw, though Im not sure which version mingw.
Anyone know why this happened?
It sounds to me like your parameter is not really a Boolean value at all. You have a floating point parameter with special cases for the discrete numbers 0.0 and 1.0. Create two
doubleconstants instead of a type.C99 added definitions for the type
_Bool, a macrobool, a macrotrue, and a macrofalse. Try inserting the following in your header:If any of these fire, then you are including stdbool.h somewhere. You should be able to
#undefthe three macros and then set up your types safely. Of course, this will probably break if someone else expectsboolto be a small integer value and has more style problems that you can shake a stick at.ISO/IEC 9899:1999 does make a concession to the fact that many groups have already defined their own Boolean types before it was added to the Standard. This is the rationale for defining
bool,true, andfalseas macros instead of new keywords. However, the following warning is explicitly included: