opensubscriber
   Find in this group all groups
 
Unknown more information…

e : emacs-devel@gnu.org 28 January 2008 • 9:19PM -0500

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

REPLY TO AUTHOR
 
REPLY TO GROUP



2008-01-28  Jim Meyering  <meyering@redh...>

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 <meyering@redh...>
---
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


_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu....
http://lists.gnu.org/mailman/listinfo/emacs-devel

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.