[Top][All Lists]

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

Re: [Nmh-workers] Changing the return type of done()

From: Peter Maydell
Subject: Re: [Nmh-workers] Changing the return type of done()
Date: Tue, 17 Apr 2007 09:19:59 +0100

Joel Reicher wrote:
>At the moment done() returns int, but it does this *only* because it is
>used at the end of main()s as
>return done (status);
>Every definition of done() I've been able to find (it's overridden in
>some compilation units) has the line
>return 1;  /* dead code to satisfy the compiler */
>at the end solely because of this calling context.
>While it makes some sense to provide this dead code in main(), I believe
>it is bad programming practice to hide it in a function that would not
>otherwise contain it for any other reason.
>I'd like to change done() to return void, and replace all the main()
>calls with the two lines
>return 1;
>I write "return 1;" there only because it's entirely equivalent to what's
>currently in the code. All the done() implementations call exit(), so
>the line should never be reached.

Ah, you've run into this too. I was halfway through trying to change
this to remove the compiler warnings.

I'd also be in favour of putting this in h/prototypes.h:
 /* If this is GCC, we can specify some attributes to help the compiler
  * (a) generate better code and (b) avoid spurious warnings.
  * If this isn't GCC, the attributes are ignored.
 #ifdef __GNUC__
 #define NORETURN __attribute__ ((__noreturn__))
 #define NOTUSED __attribute__ ((__unused__))
 #define NORETURN
 #define NOTUSED

and then having the prototype for done() (and adios() too) look like
 void done (int) NORETURN;

I'm tempted to suggest dumping the unreachable 'return 1;' lines too...

(Returning void also has the advantage that create_folder()'s second
argument can be given the right type.)

-- PMM

reply via email to

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