Article View: comp.lang.c.moderated
Article #2381Re: Macros and Braces
From: news
Date: Sun, 24 Mar 1996 17:50
Date: Sun, 24 Mar 1996 17:50
28 lines
1313 bytes
1313 bytes
In article <4j06iu$7qm@solutions.solon.com>,
Antony Pace (UK/CH) <100576.1776@compuserve.com> wrote:
>I am having problems writing a macro (Ansi C) for which I feel there
>must be standard technique. Can anyone help?
>
>Here is my first attempt at the macro. I have defined an error type
>which is a small structure with 3 variables in it. I want to use a
>macro to clear all the variables so that if the number or type of
>variables change, only my macro has to change.
>
>typedef struct {
> int a;
> int b;
> int c;
>} t_error;
>
>#define CLEAR_ERROR(e) { \
> (e).a = 0; \
> (e).b = 0; \
> (e).c = 0; \
> TRACE("clear error"); \
>}
what about:
#define CLEAR_ERROR(e) \
( (e).a = (e).b = (e).c = 0, TRACE( "clear error" ) )
where TRACE(s) is:
#define TRACE(s) ( traceon ? fprintf( ... ) : 0 )
Technical Details
Message-ID:
<4j421k$nve@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4j06iu$7qm@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: news@rose.com (news) Newsgroups: comp.lang.c.moderated Subject: Re: Macros and Braces Date: 24 Mar 1996 11:50:44 -0600 Organization: Rose Media Incorpoarted, Ontario, Canada Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4j421k$nve@solutions.solon.com> References: <4j06iu$7qm@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com