🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2375

Re: Macros and Braces

#2375
From: Roger Ramhoff
Date: Sun, 24 Mar 1996 17:48
43 lines
1555 bytes
Antony Pace (UK/CH) wrote:
> 
> Can anyone help?
> 
> Here is my first attempt at the macro.
> 
> #define CLEAR_ERROR(e) { \
>   (e).a = 0;             \
>   (e).b = 0;             \
>   (e).c = 0;             \
>   TRACE("clear error");  \
> }
> 
> In this code segment, my macro does not work:
> 
>   ...
>   if (a==3)
>     CLEAR_ERROR(error);
>   else
>     b=5;

Well, I'm not much of a theoretician, so perhaps my answer won't count
for much.

Anyway, if I were you, I'd publish that the call of the CLEAR_ERROR(e)
macro (especially as an if/else clause) should either

    a)  always be within braces -- { CLEAR_ERROR (e) }
or
    b)  never be followed by a semicolon --  CLEAR_ERROR (e)

My personal style choice would be 'a'.  I use that style so that I can
always expand an if/else clause without forgetting to add a brace.  I
just plain don't care that it may add extra white space.

Just my 2c.
-- 

Roger Ramhoff
It *can* be better

Field Consultant			William.R.Ramhoff@cdc.com
Control Data Systems			(810) 262-8235
Technical Details
Message-ID: <4j41sl$nr2@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4j06iu$7qm@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: Roger Ramhoff <rramhoff@dtrhp01.dtr.cdc.com>
Newsgroups: comp.lang.c.moderated
Subject: Re: Macros and Braces
Date: 24 Mar 1996 11:48:05 -0600
Organization: Control Data Systems, Inc.
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4j41sl$nr2@solutions.solon.com>
References: <4j06iu$7qm@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.07 9000/735)