I have a piece of legacy code that has got char*
function arguments which are used for if-then-else logical flow. For example:
void myFunc(char *f_reset) {
.....
.....
if(*f_reset) {// do this;}
else {// do that;}
}
suppose I am calling myFunc(char *f_reset)
from main()
void main(void) {
char r = 0;
char *f_reset = &r;
*f_reset = 0;
myFunc(f_reset); // Debug and enter this function
}
When I try to enter the function call, I find out that *f_reset
is never evaluated as 0
i.e. false - it is always true because of some garbage -8342345825
or something like that.
The reason it is using char*
is probably because in the old days boolean took more memory than char *? Some stuff I read in the past in Stackoverflow posts.
Could someone give me a dummy's guide for the relationship between char*
and logical true false?