long cread(long *xp) {
return (xp? *xp : 0);
}
It is invalid since it could attempt to read from a null address
So the solution suggested this code
long cread_alt(long *xp){
long tem = 0;
if(*xp > 0){
tem = *xp;
}
return tem;
But I think it is also not valid since if(*xp > 0)
is still defective when the xp
is pointing a null address.
So I thought this code
long cread_alt2(long *xp){
long tem = 0;
if(xp != NULL){
tem = *xp;
}
return tem;
}
Do I have this correct?