Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 2/2] Fix two C nits



On 2018-06-18 10:22:41 +0100, Peter Stephenson wrote:
> On Sat, 16 Jun 2018 01:04:27 +0000
> Eitan Adler <lists@xxxxxxxxxxxxxx> wrote:
> > - avoid returning from a function that will never return
> >
> > diff --git a/Src/exec.c b/Src/exec.c
> > index d44527841..b36bcef64 100644
> > --- a/Src/exec.c
> > +++ b/Src/exec.c
> > @@ -4954,7 +4954,6 @@ getpipe(char *cmd, int nullexec)
> >      execode(prog, 0, 1, out ? "outsubst" : "insubst");
> >      cmdpop();
> >      _exit(lastval);
> > -    return 0;
> >  }
> 
> I'm not 100% sure about this since you're relying on the compiler
> knowing that _exit won't return.  Probably the majority of compilers
> we're involved with for zsh will work that out, but I'm not sure
> it's actually required by the C standard that they know the function
> doesn't return, is it?  You may know some corner I haven't investigated.

AFAIK, it's only useful for optimization and optional diagnostics.

The _exit function is non-standard. So, it depends on whether it is
declared as _Noreturn or not. FYI, the standard C11 function is:

  _Noreturn void _Exit(int status);

Perhaps use it, and _exit as a fallback.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author