bug-cfengine
[Top][All Lists]
Advanced

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

Re: Problems concerning preprocessor macros in ifconf.c


From: David Masterson
Subject: Re: Problems concerning preprocessor macros in ifconf.c
Date: 26 Mar 2002 08:14:22 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

>>>>> Martin Jost writes:

> Hello,

> while compiling cfengine 2.0.0 I got two warnings from the cpp on
> HPUX 10.20 using HP ANSI C.  HPs cpp doesn't know about something
> like '# else if'. It just takes the '#else', throws away the 'if'
> and spits out a warning.  The second '#else if' seems to be
> wrong. There is an 'if' but no condition.  I fixed this like this:

> --------------------------- snip, snip -----------------------------
> --- src/ifconf.c      26 Mar 2002 15:05:24 -0000      1.2
> +++ src/ifconf.c      26 Mar 2002 15:06:55 -0000
> @@ -365,7 +365,7 @@
 
>  # ifdef HAVE_ORTENTRY
>     struct ortentry route;
> -# else if HAVE_RTENTRY
> +# elif HAVE_RTENTRY
>     struct rtentry route;
>  # endif
 
> @@ -460,7 +460,7 @@
>     CfLog(cferror,OUTPUT,"");
>     }
 
> -# else if
> +# else
 
>  /* Socket routing - don't really know how to do this yet */
> --------------------------- snip, snip ----------------------------- 

> I hope this is usable for other compilers too ?!

If I recall correctly, some compilers preferred "#else if" while
others preferred "#elif" (ANSI is "#elif").  So, for the greatest
portability, this should probably be written as:

#ifdef HAVE_ORTENTRY
...
#else
#ifdef HAVE_RTENTRY
...
#endif
#endif

Did you test your "else if"?  I don't think that does what you want.
I think it should be written as:

#elif defined(HAVE_RTENTRY)

Oh, that's right -- HAVE_RTENTRY gets #defined as '1' in config.h, so
your way would work as well.  However, the test should be more
explicit (ie. test for "defined" or test for a value).

-- 
David Masterson                dmaster AT synopsys DOT com
Sr. R&D Engineer               Synopsys, Inc.
Software Engineering           Sunnyvale, CA



reply via email to

[Prev in Thread] Current Thread [Next in Thread]