Thimble Liu
2020-04-14 13:58:41 UTC
I'm reading the code of lcc, and also the book. And I'm stucking at the function isnullptr(Tree e), in file enode.c. The function is below:
static int isnullptr(e) Tree e; {
return (isint(e->type) && generic(e->op) == CNST
&& cast(e, unsignedtype)->u.v.u == 0)
|| (isvoidptr(e->type) && e->op == CNST+P
&& e->u.v.p == NULL);
}
I've checked the ANSI C standard about the null pointer and the null pointer constant, and still can't see how the return of isnullptr connect about the standard about null pointer or null pointer constant.
I also read the code of cast, does (isvoidptr(e->type) && e->op == CNST+P && e->u.v.p == NULL) implies that "a integer constant expression which value is 0 cast to type void *"? If so, why the op->e should be CNSP+P, as the code of lex.c suggested 0 is processed into a CNST+I tree? Is it caused by constant folding?
Really hope to get help! Thanks!
static int isnullptr(e) Tree e; {
return (isint(e->type) && generic(e->op) == CNST
&& cast(e, unsignedtype)->u.v.u == 0)
|| (isvoidptr(e->type) && e->op == CNST+P
&& e->u.v.p == NULL);
}
I've checked the ANSI C standard about the null pointer and the null pointer constant, and still can't see how the return of isnullptr connect about the standard about null pointer or null pointer constant.
I also read the code of cast, does (isvoidptr(e->type) && e->op == CNST+P && e->u.v.p == NULL) implies that "a integer constant expression which value is 0 cast to type void *"? If so, why the op->e should be CNSP+P, as the code of lex.c suggested 0 is processed into a CNST+I tree? Is it caused by constant folding?
Really hope to get help! Thanks!