bug-ddrescue
[Top][All Lists]
Advanced

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

Re: [Bug-ddrescue] [PATCH 3/5] io: Add missing prototype


From: Rosen Penev
Subject: Re: [Bug-ddrescue] [PATCH 3/5] io: Add missing prototype
Date: Mon, 5 Aug 2019 11:23:25 -0700

On Mon, Aug 5, 2019 at 11:08 AM Antonio Diaz Diaz <address@hidden> wrote:
>
> Rosen Penev wrote:
> >>> +extern "C" void sighandler( int signum );
> >>>    extern "C" void sighandler( int signum )
> >>>      { if( signum_ == 0&&   signum>   0 ) signum_ = signum; }
> >>
> >> There is nothing missing here. A function definition is a function
> >> declaration in which the body of the function is presented. Therefore
> >> there is no need to declare the function twice.
> >
> > My understanding here is that this function needs to be static or
> > declared separately. static cannot be used with extern so I went for
> > the other option.
>
> Why does it need to be static or declared separately? I can see nothing
> in the C++ standard requiring that. AFAICT, all that is required is that
> the function is declared before being used, and a definition is also a
> declaration.
In the case of static, it's a huge help to the compiler in terms of
figuring out if the function is used only in the file and as a result,
inlining the function which reduces the overall size.

-Wmissing-prototypes is not valid for C++ but is valid for C. From the GCC docs:

Warn if a global function is defined without a previous prototype
declaration. This warning is issued even if the definition itself
provides a prototype. Use this option to detect global functions that
do not have a matching prototype declaration in a header file. This
option is not valid for C++ because all function declarations provide
prototypes and a non-matching declaration declares an overload rather
than conflict with an earlier declaration. Use -Wmissing-declarations
to detect missing declarations in C++.



reply via email to

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