What is the right way to use logical operators with size_t
and pid_t
types?
I mean: is legal to write something like the following?
e.g.:
size_t sz;
/* some kind of assignment */
if(sz > 0){
/* do something */
}
e.g.:
void f(pid_t pid,...){
if(pid > 0){
/* do something */
}
/* ... */
}
..or I have to do some cast?
EDIT
ok for answers;
now, considered what has been told, can someone give me a reason for coding that way:
void *my_malloc(size_t size){
if(size <= 0){
return NULL;
}
/* something else... */
}
My teacher wrote that code.
Does it make sense?
I don't know how many bits are reserved for size_t
type(it is implementation-dependent)
but surely it is an unsigned(your answer), so why the above expression?