My code fragment contains (36 and 37 are line numbers):
36 char* colon_unit = extract_colon_unit( zPath, path, &p_index);
37 if (colon_unit == NULL)
During compilation, I get a warning:
a.c:36: warning: initialization makes pointer from integer without a cast
When I remove the pointer,
char colon_unit = extract_colon_unit( zPath, path, &p_index );
it shows:
a.c:37: warning: comparison between pointer and integer
How can I fix it?
This means that the function
extract_colo_unit()is returning a character (char) and not a character pointer (char*). When you change the data type ofcolon_unitto char then you won’t get the first error as now the variable and the value assigned, both have the same type.But when you compare the
colon_unitto NULL then you are comparing a character, that is,colon_unitto a pointer. That is, NULL is defined as(void*)0, so you get the second error on line 37.The solution totally depends on your logic and what it means to return NULL from this function. But if it’s an error case or a case when there is no valid value, it simply returns 0 instead of NULL and compares against 0 in line 37.