From: Jim Meyering <jim@meyering.net>
To: emacs-devel@gnu.org
Subject: [PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions.
Date: Mon, 28 Jan 2008 14:19:56 +0100 [thread overview]
Message-ID: <877ihu84ub.fsf@rho.meyering.net> (raw)
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
next reply other threads:[~2008-01-28 13:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-28 13:19 Jim Meyering [this message]
2008-02-04 20:42 ` [PATCH] Use "do...while (0)", not "if (1)..else" in macro definitions Jim Meyering
2008-02-05 7:09 ` Jan Djärv
2008-02-07 12:56 ` Jan Djärv
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877ihu84ub.fsf@rho.meyering.net \
--to=jim@meyering.net \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).