Reputation: 303
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?
Upvotes: 0
Views: 3222
Reputation: 13692
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 of colon_unit
to 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_unit
to NULL then you are comparing a character, that is, colon_unit
to 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.
Upvotes: 2