![]() |
|
|
#1 |
|
May 2014
3·11 Posts |
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 ||
|
|
|
|
|
|
#2 |
|
P90 years forever!
Aug 2002
Yeehaw, FL
2·53·71 Posts |
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) 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. |
|
|
|
|
|
#3 |
|
P90 years forever!
Aug 2002
Yeehaw, FL
752610 Posts |
BTW, you'll probably find a lot more needless (char *) typecasts if you look real hard.
|
|
|
|
|
|
#4 | |
|
May 2014
3·11 Posts |
Quote:
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. |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Patch] Fix strcpy misuse in getProxyInfo() | Explorer09 | Software | 1 | 2017-03-01 22:03 |
| A meaningless curiosity | fivemack | Aliquot Sequences | 2 | 2016-01-17 07:44 |
| (patch) No need for fmt_mask[] buffer | Explorer09 | Software | 12 | 2015-09-23 22:22 |
| v1.40 patch for massive NFS oversieving | jasonp | Msieve | 18 | 2009-04-09 03:20 |
| Amd patch | moo | Hardware | 6 | 2005-10-10 23:29 |