In resource-constrained systems (like an 8-bit PIC), is there any benefit to using your own macros for true and false as opposed to using those defined from stdbool?
Macros are evaluated by the pre-compiler before compile time, not by the compiler or micro at run time. A macro defined to be "1" will be replaced by "1" before the compiler even starts to try to figure out how to optimize your code. Unless your macro is better than the stdbool macro, there is no benefit.
How do they compare in terms of RAM usage? Stack usage?
1 == 1, regardless of how the macro is defined. No difference.
Code portability?
By using non-standard macros, code portability suffers. Your code will need your defines/headers, so someone can't copy and paste a section that looks standard without getting errors. Especially with something like "True" or "False".
Code simplicity?
If you don't need all of stdbool, sure, defining your own might be simpler. That's really an opinion thing.
Update:
As far as stack usage, I mean to ask what gets returned in each case? 8bits? 16bits? register size of microcontroller?
This is a better question. It's a bit complicated. First, "bool" is really a macro for "_Bool", a c99 data type. Typically, _Bool is the smallest addressable object capable of holding a 0 or a 1. That's a char, an 8 bit sized object. (Things like nibbles are overly complicated objects that have some background code required to split a single 8 bit char into two "separate" 4 bit objects). _Bool also has some logic to where it's 0 when 0, or 1 when anything over or under 0. _bool random_variable = 5
would result in random_variable equaling 1. Memory wise, that bool will be 8 bits, but return literal 0 or 1.
Second, true and false, as you have created macro for, are exactly the same as stdbool.h defines true and false. A literal 0 or 1. Literal intergers are by default, int data types. int is not a fixed standard. It can be defined by your IDE, or compiler, or language. It changes by microcontroller manufacturer or even line of microcontrollers by same manufacturer. It can also be signed or unsigned for the same reasons (See: https://stackoverflow.com/questions/589575/size-of-int-long-etc ) So unless you typecast a variable when assigning true
or false
, it will be upcasted to int. But uint8_t is a stdint.h unsigned data type of 8 bits as well.
Third, your two functions are not exactly alike. Realize, that IsThisGood returns a bool (really _Bool) type (char/8 bit object). IsThisBetter returns a uint8_t type (8 bits). In practice, the same, but _Bool type has logic to make anything greater than 0 = 1, while uint8_t does not. IsThisBetter could technically return 255 for some reason.
Finally, if for some reason "char" on your microcontroller/ide/compiler/language is greater than 8 bits, then your uint_8 version will be smaller, memory wise, but still lack the "greater than 0 = 1" logic.
See this stack overflow answer on size of _Bool: https://stackoverflow.com/a/10630231/1498667