mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2017-02-22, 15:49   #1
Explorer09
 
May 2014

3×11 Posts
Default [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 ||
Explorer09 is offline   Reply With Quote
Old 2017-03-01, 02:57   #2
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

1E0316 Posts
Default

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)
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.
Prime95 is online now   Reply With Quote
Old 2017-03-01, 02:58   #3
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

170038 Posts
Default

BTW, you'll probably find a lot more needless (char *) typecasts if you look real hard.
Prime95 is online now   Reply With Quote
Old 2017-03-01, 09:55   #4
Explorer09
 
May 2014

3×11 Posts
Default

Quote:
Originally Posted by Prime95 View Post
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)
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.
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.
Explorer09 is offline   Reply With Quote
Reply

Thread Tools


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

All times are UTC. The time now is 17:21.


Fri Dec 3 17:21:31 UTC 2021 up 133 days, 11:50, 2 users, load averages: 1.56, 1.37, 1.28

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.