![]() |
[Patch] Fix meaningless (char (*)[13]) to (char *) cast
Not a bug, but to fix a code readability problem.
A pointer to array is rarely useful in C. Here, passing m_start_time instead of &m_start_time as function arguments is what the code intended. (In prime95 / mprime "menu.c") [CODE]diff -r -u a/linux/menu.c b/linux/menu.c --- a/linux/menu.c 2016-09-15 10:15:10.000000000 +0800 +++ b/linux/menu.c 2017-02-22 23:30:39.806257928 +0800 @@ -866,8 +866,8 @@ askNum ("Daytime P-1/ECM stage 2 memory in MB", &m_day_memory, 8, max_mem); askNum ("Nighttime P-1/ECM stage 2 memory in MB", &m_night_memory, 8, max_mem); if (m_day_memory != m_night_memory) { - askStr ("Daytime begins at", (char *) &m_start_time, 12); - askStr ("Daytime ends at", (char *) &m_end_time, 12); + askStr ("Daytime begins at", m_start_time, 12); + askStr ("Daytime ends at", m_end_time, 12); } } @@ -887,8 +887,8 @@ delete_timed_event (TE_COMM_SERVER); UpdateEndDates (); } - new_day_start_time = strToMinutes ((char *) &m_start_time); - new_day_end_time = strToMinutes ((char *) &m_end_time); + new_day_start_time = strToMinutes (m_start_time); + new_day_end_time = strToMinutes (m_end_time); if (m_memory_editable && (day_memory != m_day_memory || night_memory != m_night_memory ||[/CODE] |
My personal style, not rigidly adhered to over the years, is to use
[CODE] some_proc_not_modifying_int_var (int_variable) some_proc_not_modifying_char_var (char_variable) some_proc_modifying_int_var (&int_variable) some_proc_modifying_char_var (&char_variable) [/CODE] so that the & is a quick clue to the reader that the proc being called may be modifying the variable. Unfortunately, somewhere over the last 20 years, one or more compilers started whining about "some_proc_modifying_char_var (&char_variable)" saying that &char[13] is not compatible with proc expecting char *. Thus, I tossed in the (char *) cast. Since I'm no fan of needless casts, I've made the change as you suggested. |
BTW, you'll probably find a lot more needless (char *) typecasts if you look real hard.
|
[QUOTE=Prime95;454015]My personal style, not rigidly adhered to over the years, is to use
[CODE] some_proc_not_modifying_int_var (int_variable) some_proc_not_modifying_char_var (char_variable) some_proc_modifying_int_var (&int_variable) some_proc_modifying_char_var (&char_variable) [/CODE] so that the & is a quick clue to the reader that the proc being called may be modifying the variable. Unfortunately, somewhere over the last 20 years, one or more compilers started whining about "some_proc_modifying_char_var (&char_variable)" saying that &char[13] is not compatible with proc expecting char *. Thus, I tossed in the (char *) cast. Since I'm no fan of needless casts, I've made the change as you suggested.[/QUOTE] I have already got used to the C convention that for some_proc_modifying_C_string (pointer_to_char) the string argument does not need an "&" operator. It might be just me, but if I'm going to indicate a string argument will never be modified, I'll just make the parameter type (const char *) on the prototype. |
| All times are UTC. The time now is 20:37. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.