0
votes

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?

1
What does extract_colon_unit return? - interjay
How is your extract_colon_unit declared? Is the declaration before the using occurrence? - Basile Starynkevitch
Plese post declaration of extract_colon_unit(). - Martin James
Also, maybe rename it? It sounds like some sort of painful surgery.. - Martin James

1 Answers

2
votes

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.