Skip to contentSkip to conversation

gettext.h: Avoid using a non-standard C construct

PATCH In review Ramsay Jones 4 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 6/9 gettext.h: Avoid using a non-standard C construct

In particular, standard C does not allow a parenthesized string as an array initializer. Some compilers, for example GCC and MSVC, allow this syntax as an extension, but it is (obviously) not a portable construct.

In order to avoid such a construct, for example while initialising the array 'ignore_error' (builtin/add.c line 309), we simply remove the parenthesis from the definition of the N_() macro.

---

For example, tcc can not parse this syntax.

Note that sparse issues warnings like the following:
builtin/add.c:309:1: warning: too long initializer-string for \
array of char
which is actually a bug in sparse that is tickled by a parenthesized string initializer (it doesn't determine the correct size of the string). Again I have a patch ...

 gettext.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
gettext.h +1 -1
index 1b253b7..24d9182 100644
@@ -35,6 +35,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
 }
 
 /* Mark msgid for translation but do not translate it. */
-#define N_(msgid) (msgid)
+#define N_(msgid) msgid
 
 #endif
Signature · 1 line
1.7.4
Acked-by on v1 6/9
#1 lore raw

Hi,

Quoted 2 lines · Ramsay Jones

+++ b/gettext.h

(quoted diff) +0 -0
@@ -35,6 +35,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)

[...]

gettext.h const char *Q_(const char *msgid, const char *plu, unsigned long n) · line 38

Quoted 2 lines
gettext.h +1 -1
-#define N_(msgid) (msgid)
+#define N_(msgid) msgid

Good catch. Thanks!

Quoted 2 lines

In particular, standard C does not allow a parenthesized string as an array initializer.

The subject line seems unnecessarily vague. Why not:

i18n: avoid parenthesized string as array initializer

The syntax

static const char ignore_error[] = ("something");

is invalid C. GCC and MSVC can parse it, but for example tcc cannot. So remove the parenthesis from the definition of the N_() macro.

#2 lore raw
Quoted 17 lines · Jonathan Nieder
Quoted 2 lines

+++ b/gettext.h

(quoted diff) +0 -0
@@ -35,6 +35,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)

[...]

gettext.h const char *Q_(const char *msgid, const char *plu, unsigned long n) · line 38

Quoted 2 lines
gettext.h +1 -1
-#define N_(msgid) (msgid)
+#define N_(msgid) msgid

Good catch. Thanks!

Quoted 2 lines

In particular, standard C does not allow a parenthesized string as an array initializer.

The subject line seems unnecessarily vague. Why not:

i18n: avoid parenthesized string as array initializer

The syntax

Quoted 9 lines

static const char ignore_error[] = ("something");

is invalid C. GCC and MSVC can parse it, but for example tcc cannot. So remove the parenthesis from the definition of the N_() macro.

Sounds good to me. I'll re-roll and use your message verbatim.

Thanks!

ATB,
Ramsay Jones

#4 lore raw
In reply to Jonathan Nieder
Quoted 21 lines · Jonathan Nieder

Hi,

Quoted 2 lines · Ramsay Jones

+++ b/gettext.h

(quoted diff) +0 -0
@@ -35,6 +35,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)

[...]

gettext.h const char *Q_(const char *msgid, const char *plu, unsigned long n) · line 38

Quoted 2 lines
gettext.h +1 -1
-#define N_(msgid) (msgid)
+#define N_(msgid) msgid

Good catch.  Thanks!

Quoted 2 lines

In particular, standard C does not allow a parenthesized string as an array initializer.

The subject line seems unnecessarily vague.  Why not:

       i18n: avoid parenthesized string as array initializer

       The syntax

Quoted 8 lines

               static const char ignore_error[] = ("something");

       is invalid C.  GCC and MSVC can parse it, but for example tcc cannot.  So remove the parenthesis from the definition of the N_() macro.

This looks good to me with this commit message: