Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] lojza.h: release early, release often . . . . . . . .



Yum, troll.  I like troll.  *Chomp* ;-)

On 28/07/06, Stephen J. Turnbull <stephen@example.com> wrote:
>>>>> "Jim" == Jim  <jep200404@example.com> writes:

    Jim> I've learned to add parentheses around #define values as a
    Jim> matter of routine to avoid suprises.

Good luck!  There are all kinds of ways this can trip you up if you're
actually doing anything complex enough for it to help.

I think it's safer to put them in than not, because you're reducing
the number of circumstances where you get bitten.  Generally a good
idea to stick brackets around parameters used in defines too...

Really, you
should be aiming at exactly the necessary number of parentheses.

#define thing(a, b, c) a&b|c  /* let's say this is exactly what you
meant, with the minimum number of parentheses */
retval=thing(x|y, z&w, v)&e|f  /* however, this almost certainly isn't
what you meant at all */

If
it starts turning into work to get them right, it's time to think
about strategies for avoiding use of #define.

This is what made me bite.  #define is crufty, I agree, but inline is
not C89 (and most compilers aren't C99, and since I'm on a project
with no fixed processor or toolchain at the moment I'm quite
appreciative of people who keep their code portable).   And enum
{x=1.23} simply doesn't work.

--
Ian.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links