emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions.


From: Jim Meyering
Subject: [PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions.
Date: Mon, 28 Jan 2008 14:19:56 +0100

2008-01-28  Jim Meyering  <address@hidden>

        Use "do...while (0)", not "if (1)..else" in macro definitions.
        The latter provokes a warning from gcc about the empty else, when
        followed by ";".  Also, without that trailing semicolon, it would
        silently swallow up any following statement.
        * syntax.h (SETUP_SYNTAX_TABLE):
        (SETUP_SYNTAX_TABLE_FOR_OBJECT): Likewise.
        * buffer.h (DECODE_POSITION): Likewise.
        * charset.h (FETCH_STRING_CHAR_ADVANCE): Likewise.
        (FETCH_STRING_CHAR_ADVANCE_NO_CHECK): Likewise.
        (FETCH_CHAR_ADVANCE): Likewise.

Signed-off-by: Jim Meyering <address@hidden>
---
 src/buffer.h  |    4 ++--
 src/charset.h |   14 +++++++-------
 src/syntax.h  |    8 ++++----
 4 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/buffer.h b/src/buffer.h
index 24c6fc5..2423357 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -266,7 +266,7 @@ extern void enlarge_buffer_text P_ ((struct buffer *, int));
    and store the charpos in CHARPOS and the bytepos in BYTEPOS.  */

 #define DECODE_POSITION(charpos, bytepos, pos)                 \
-if (1)                                                         \
+do                                                             \
   {                                                            \
     Lisp_Object __pos = (pos);                                 \
     if (NUMBERP (__pos))                                       \
@@ -282,7 +282,7 @@ if (1)                                                      
        \
     else                                                       \
       wrong_type_argument (Qinteger_or_marker_p, __pos);       \
   }                                                            \
-else
+while (0)

 /* Return the address of byte position N in current buffer.  */

diff --git a/src/charset.h b/src/charset.h
index de7a16a..6e60ae1 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -582,7 +582,7 @@ extern int iso_charset_table[2][2][128];
    we increment them past the character fetched.  */

 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX)       \
-if (1)                                                                    \
+do                                                                        \
   {                                                                       \
     CHARIDX++;                                                            \
     if (STRING_MULTIBYTE (STRING))                                        \
@@ -597,17 +597,17 @@ if (1)                                                    
                   \
     else                                                                  \
       OUTPUT = SREF (STRING, BYTEIDX++);                                  \
   }                                                                       \
-else
+while (0)

 /* Like FETCH_STRING_CHAR_ADVANCE but assume STRING is multibyte.  */

 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX)  \
-if (1)                                                                       \
+do                                                                           \
   {                                                                          \
     const unsigned char *fetch_string_char_ptr = SDATA (STRING) + BYTEIDX;    \
     int fetch_string_char_space_left = SBYTES (STRING) - BYTEIDX;            \
     int actual_len;                                                          \
-                                                                             \
+                                                                             \
     OUTPUT                                                                   \
       = STRING_CHAR_AND_LENGTH (fetch_string_char_ptr,                       \
                                fetch_string_char_space_left, actual_len);    \
@@ -615,13 +615,13 @@ if (1)                                                    
                      \
     BYTEIDX += actual_len;                                                   \
     CHARIDX++;                                                               \
   }                                                                          \
-else
+while (0)

 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current
    buffer.  */

 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX)                     \
-if (1)                                                                   \
+do                                                                       \
   {                                                                      \
     CHARIDX++;                                                           \
     if (!NILP (current_buffer->enable_multibyte_characters))             \
@@ -639,7 +639,7 @@ if (1)                                                      
                  \
        BYTEIDX++;                                                        \
       }                                                                        
  \
   }                                                                      \
-else
+while (0)

 /* Return the length of the multi-byte form at string STR of length LEN.  */

diff --git a/src/syntax.h b/src/syntax.h
index b3980c3..809990b 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -283,7 +283,7 @@ extern char syntax_code_spec[16];
  */

 #define SETUP_SYNTAX_TABLE(FROM, COUNT)                                        
\
-if (1)                                                                 \
+do                                                                     \
   {                                                                    \
     gl_state.b_property = BEGV;                                                
\
     gl_state.e_property = ZV + 1;                                      \
@@ -296,7 +296,7 @@ if (1)                                                      
                \
         update_syntax_table ((COUNT) > 0 ? (FROM) : (FROM) - 1, (COUNT),\
                             1, Qnil);                                  \
   }                                                                    \
-else
+while (0)

 /* Same as above, but in OBJECT.  If OBJECT is nil, use current buffer.
    If it is t, ignore properties altogether.
@@ -306,7 +306,7 @@ else
    So if it is a buffer, we set the offset field to BEGV.  */

 #define SETUP_SYNTAX_TABLE_FOR_OBJECT(OBJECT, FROM, COUNT)             \
-if (1)                                                                 \
+do                                                                     \
   {                                                                    \
     gl_state.object = (OBJECT);                                                
\
     if (BUFFERP (gl_state.object))                                     \
@@ -341,7 +341,7 @@ if (1)                                                      
                \
                            + (COUNT > 0 ? 0 :  -1)),                   \
                           COUNT, 1, gl_state.object);                  \
   }                                                                    \
-else
+while (0)

 struct gl_state_s
 {
--
1.5.4.rc5.1.g0fa73




reply via email to

[Prev in Thread] Current Thread [Next in Thread]