Unnecessary Parenthesis
steve
steve at oakhill.UUCP
Tue Jul 26 05:07:25 AEST 1988
I'm sorry I can't include the text I'm mentioning since I'm haveing net
reply problems, but I'll fake it as best I can.
In an absolute sense
> #define square(x) (x * x)
shouldn't be :
> #define square(x) ((x) * (x))
it should be :
> #define square(x) (temp = (x),(temp * temp))
in order to avoid problems with sending in a post incremented variable;
BUT, - as with everything else in C, either of the first two forms
are good if you're careful and know what you're doing. Form 1 works
if you know you're sending in a simple variable. Form 2 works
if you are not sending in an expression that changes the variable.
Form 3 is slower than the other two, but more conservative.
Use your best judgement - macros are dangerous thing if not used carefully
That is why C compilers have a -P option.
Your mooncalf - Steve
To: paul at zaphod.UChicago.Edu
Subject: Re: Unnecessary Parenthesis
Newsgroups: comp.lang.c
In-Reply-To: <441 at kaon.uchicago.edu>
References: <2089 at ssc-vax.UUCP>
Organization: Motorola Inc., Austin Tx.
Cc:
Bcc:
I'm sorry I can't include the text I'm mentioning but
> #define square(x) (x * x)
shouldn't be :
> #define square(x) ((x) * (x))
it should be :
> #define square(x) (temp = (x),(temp * temp))
in order to avoid problems with sending in a post incremented variable;
BUT, - as with everything else in C, either of the first two forms
are good if you're careful and know what you're doing. Form 1 works
if you know you're sending in a simple variable. Form 2 works
if you are not sending in an expression that changes the variable.
Form 3 is slower than the other two, but more conservative.
Your mooncalf - Steve
>From steve Mon Jul 25 13:54:49 1988
Return-Path: <steve>
Received: by devsys.com (3.2/SMI-3.2)
id AA13794; Mon, 25 Jul 88 13:54:49 CDT
Date: Mon, 25 Jul 88 13:54:49 CDT
From: steve
Message-Id: <8807251854.AA13794 at devsys.com>
To: paul at zaphod.UChicago.Edu
Subject: Re: Unnecessary Parenthesis
Newsgroups: comp.lang.c
In-Reply-To: <441 at kaon.uchicago.edu>
References: <2089 at ssc-vax.UUCP>
Organization: Motorola Inc., Austin Tx.
Cc:
I'm sorry I can't include the text I'm mentioning but having sending
problems. I'l try to fake it.
> #define square(x) (x * x)
shouldn't be :
> #define square(x) ((x) * (x))
it should be :
> #define square(x) (temp = (x),(temp * temp))
in order to avoid problems with sending in a post incremented variable;
BUT, - as with everything else in C, either of the first two forms
are good if you're careful and know what you're doing. Form 1 works
if you know you're sending in a simple variable. Form 2 works
if you are not sending in an expression that changes the variable.
Form 3 is slower than the other two, but more conservative.
Your mooncalf - Steve
To: paul at zaphod.UChicago.Edu
Subject: Re: Unnecessary Parenthesis
Newsgroups: comp.lang.c
In-Reply-To: <441 at kaon.uchicago.edu>
References: <2089 at ssc-vax.UUCP>
Organization: Motorola Inc., Austin Tx.
Cc:
Bcc:
I'm sorry I can't include the text I'm mentioning but
> #define square(x) (x * x)
shouldn't be :
> #define square(x) ((x) * (x))
it should be :
> #define square(x) (temp = (x),(temp * temp))
in order to avoid problems with sending in a post incremented variable;
BUT, - as with everything else in C, either of the first two forms
are good if you're careful and know what you're doing. Form 1 works
if you know you're sending in a simple variable. Form 2 works
if you are not sending in an expression that changes the variable.
Form 3 is slower than the other two, but more conservative.
Your mooncalf - Steve
To: paul at zaphod.UChicago.Edu
Subject: Re: Unnecessary Parenthesis
Newsgroups: comp.lang.c
In-Reply-To: <441 at kaon.uchicago.edu>
References: <2089 at ssc-vax.UUCP>
Organization: Motorola Inc., Austin Tx.
Cc:
Bcc:
I'm sorry I can't include the text I'm mentioning but having sending
problems. I'l try to fake it.
> #define square(x) (x * x)
shouldn't be :
> #define square(x) ((x) * (x))
it should be :
> #define square(x) (temp = (x),(temp * temp))
in order to avoid problems with sending in a post incremented variable;
BUT, - as with everything else in C, either of the first two forms
are good if you're careful and know what you're doing. Form 1 works
if you know you're sending in a simple variable. Form 2 works
if you are not sending in an expression that changes the variable.
Form 3 is slower than the other two, but more conservative.
Your mooncalf - Steve
> Nothing I say is quoteable - so don't expect to see anything important here.
More information about the Comp.lang.c
mailing list