[PATCH] Properly encapsulate multi-statement macro.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Properly encapsulate multi-statement macro.

Hans-Bernhard Bröker

  winsup/cygwin/fhandler_console.cc | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc
b/winsup/cygwin/fhandler_console.cc
index 4ab9bcab8..353abd197 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -63,10 +63,11 @@ static struct fhandler_base::rabuf_t con_ra;
  static unsigned char wpbuf[WPBUF_LEN];
  static int wpixput;
  static unsigned char last_char;
-#define wpbuf_put(x) \
+#define wpbuf_put(x) do { \
    wpbuf[wpixput++] = x; \
    if (wpixput > WPBUF_LEN) \
-    wpixput--;
+    wpixput--; \
+} while(0)

  static void
  beep ()
--
2.21.0



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Properly encapsulate multi-statement macro.

Brian Inglis
On 2020-02-27 12:47, Hans-Bernhard Bröker wrote:

>
>  winsup/cygwin/fhandler_console.cc | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
> index 4ab9bcab8..353abd197 100644
> --- a/winsup/cygwin/fhandler_console.cc
> +++ b/winsup/cygwin/fhandler_console.cc
> @@ -63,10 +63,11 @@ static struct fhandler_base::rabuf_t con_ra;
>  static unsigned char wpbuf[WPBUF_LEN];
>  static int wpixput;
>  static unsigned char last_char;
> -#define wpbuf_put(x) \
> +#define wpbuf_put(x) do { \

Please split to avoid eye bleed:

  +#define wpbuf_put(x) \
  +do { \
>    wpbuf[wpixput++] = x; \
>    if (wpixput > WPBUF_LEN) \
> -    wpixput--;
> +    wpixput--; \
> +} while(0)
>
>  static void
>  beep ()

and post to cygwin-patches?

--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple