i'm trying troubleshoot warnings in c code compiled -std=gnuc99.
void function.. (char *argument) { int hour; hour = (int) (struct tm *)localtime(¤t_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(¤t_time)->tm_hour; ^
what assume happning here localtime not pointer , it's not same size int?
localtime(¤t_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(¤t_time)->tm_hour;
Comments
Post a Comment