all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions.
@ 2008-01-28 13:19 Jim Meyering
  2008-02-04 20:42 ` Jim Meyering
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Meyering @ 2008-01-28 13:19 UTC (permalink / raw)
  To: emacs-devel

2008-01-28  Jim Meyering  <meyering@redhat.com>

	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@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-07 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-28 13:19 [PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions Jim Meyering
2008-02-04 20:42 ` Jim Meyering
2008-02-05  7:09   ` Jan Djärv
2008-02-07 12:56   ` Jan Djärv

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.