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

Marcel Holtmann <[email protected]>
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
Hi Grant,

> 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(-)
> 
> diff --git a/src/main.c b/src/main.c
> index 241c713d7980..c01a9e59d11c 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -69,6 +69,16 @@
> #define MAINFILE "main.conf"
> #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
> 
> +/*
> + * This is declared as 'const char *const' to effect an immutable
> + * pointer to an immutable null-terminated character string such that
> + * it ends up in .text, not .data (which would otherwise be the case
> + * for a 'const char *' declaration), and with the 'static'
> + * storage/scope qualifier, the compiler can optimize its use within
> + * this file as it sees fit.
> + */
> +static const char *const general_group_name = "General";
> +

wouldn’t be

	#define GENERAL_GROUP “General”

or

	#define GROUP_GENERAL “General”

be actually more consistent with the other constants we use here.

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 :(

Regards

Marcel
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.