Re: [PATCH] main: Use static global rather than 'General' string literal.

Grant Erickson <[email protected]>
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
On Dec 27, 2023, at 3:48 AM, Marcel Holtmann <[email protected]> wrote:
>> This converts a potential run time error due to a mis-spelling of the
>> "General" configuration group name repeatedly used a string literal
>> into a potential compile time error due to a mis-spelling of the
>> static global that now references it once and only once.
>> ---
>> src/main.c | 85 +++++++++++++++++++++++++++++++-----------------------
>> 1 file changed, 49 insertions(+), 36 deletions(-)
> 
> wouldn’t be
> 
> 	#define GENERAL_GROUP “General”
> 
> or
> 
> 	#define GROUP_GENERAL “General”
> 
> be actually more consistent with the other constants we use here.

There are definitely an appreciable number of existing preprocessor definitions in this file. So, with that in mind, a preprocessor definition would be stylistically more consistent.

> I do like the all upper-case to indicate a constant here (and scrapping
> the “name” portion).
> 
> Otherwise, yes, it is stupid from us to keep using “General” in all
> places :(

At -O2 optimization, all three approaches are neutral from a code-generation perspective. So, the question comes down to one of style:

   text	   data	    bss	    dec	    hex	filename
   9817	    756	    264	  10837	   2a55	connmand-main.o // "General" string literals
   9817	    756	    264	  10837	   2a55	connmand-main.o // "General" static const char * const global
   9817	    756	    264	  10837	   2a55	connmand-main.o // "General" preprocessor macro

I’d be happy to re-submit a v2 patch with the preprocessor definition.

Best,

Grant

-- 
Principal
Nuovations

[email protected]
http://www.nuovations.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.