c - How to resolve this cast to pointer of a different size warning? -


i'm trying troubleshoot warnings in c code compiled -std=gnuc99.

void function.. (char *argument) {   int hour;    hour = (int) (struct tm *)localtime(&current_time)->tm_hour;    if(hour < 12)   {       do...something...   } } 

the warning

 warning: cast pointer integer of different size [-wint-to-pointer-cast]  hour = (int) (struct tm *)localtime(&current_time)->tm_hour;               ^ 

what assume happning here localtime not pointer , it's not same size int?

localtime(&current_time)->tm_hour has type int . cast struct tm *, producing warning. in general, conversion between pointers , int not meaningful , may cause undefined behaviour.

to avoid error, remove casts:

hour = localtime(&current_time)->tm_hour; 

Comments