4 ms·
A friend of mine actually encountered #define FALSE 1 in some header file he included from a 3rd party project. It was straight C. I'm not sure why after findi
by fleitz 15y ago
A friend of mine actually encountered #define FALSE 1 in some header file he included from a 3rd party project. It was straight C.
I'm not sure why after finding that he decided to file a bug report rather that not touch any of that code.
- asomiv 15y ago#define FALSE 1 is not that uncommon in C because C in its infinite wisdom doesn't have true/false literals so people have to invent those by themselves. Glib goes into great lengths to avoid namespace conflicts so it defines the GBoolean type and G_TRUE/G_FALSE. Whether that really is better than #define TRUE/FALSE, I don't know.
- tmp43522 15y ago#define FALSE 0 is the common one
- asomiv 15y agoDoh, you're right. I had '#define FALSE 0' in my mind. '#define FALSE 1' actually is insane.
- kklimonda 15y agoIt actually defines TRUE and FALSE, and not G_TRUE/G_FALSE. But it does indeed define the gboolean type - it does make code easier to read.
- burgerbrain 15y agoPeople don't have to invent them, and it's generally annoying as hell when they chose to.
- asomiv 15y agoSo then what are they supposed to do, require a library X which has already invented them, while your app is using library Y which already does the same thing as X?
- burgerbrain 15y agoUse 0 and 1, like everyone else. Those #defines are just meaningless syntactical sugar that get in the way.
- exDM69 15y agoIn C99 #include <stdbool.h> has the type bool and the constants true and false (even in the "freestanding" flavor). Of course this doesn't save you if you are dealing with old/non-conformant compilers and/or legacy codebases.