Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2000:
[Freeciv-Dev] Re: compiler warnings (Sun's cc on 1.10.0) (PR#269)
Home

[Freeciv-Dev] Re: compiler warnings (Sun's cc on 1.10.0) (PR#269)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jjm@xxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: compiler warnings (Sun's cc on 1.10.0) (PR#269)
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sun, 27 Feb 2000 21:31:02 +1100 (EST)

Jeff Mallatt wrote:

> >"log.c", line 141: warning: end-of-loop code not reached
> 
> Help!  I really don't understand the weird FRETURN() macro!?!?

You mean the following?
  #define FRETURN(x) do { free(dup); return (x); } while(0)

<smartass> Well, it free's the variable 'dup', and then returns
the value of the macro parameter 'x'.   ;-)

Ok, I guess you mean the "do { ... } while(0)" stuff.
This is a standard idiom to wrap up multiple statements
inside a macro, while having the macro act syntactically
like a single statement.  (Eg, classic example is a 
non-block-form "if ... else", where a multi-statment
macro would give "surprising" results otherwise.)

Solaris cc doesn't mind this idiom in general, but  
unfortunately generates a warning in this particular case.
I just checked, and changing the define to:

#define FRETURN(x) do { free(dup); if(1) return (x); } while(0)

seems to confuse Solaris cc enough to suppress the warning :-)
(And no doubt confuse future maintainers even more ;-)

-- David



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