Re: Add forward declarations
Christophe Lyon <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAKdteOapn-PE6KgZUBHH2hYLi3Ft+hfqd0+QN5Ob5tjWMMKVMw@mail.gmail.com> |
On Tue, 2 Oct 2018 at 03:04, Craig Howland <[email protected]> wrote: > > On 10/01/2018 05:37 PM, Christophe Lyon wrote: > > Hi, > > > > While building newlib for Aarch64, I noticed several warnings because > > of missing prototypes. I am not familiar enough to know why the same > > warnings do not appear when building for Arm. > > > > This patch adds the missing prototypes, tested by rebuilding for > > Aarch64 and Arm, it removed the warnings and didn't generate any > > error. > > > > OK? > > > > Christophe > A primary reason for prototypes is that they are for checking, and fully-proper > checking is a single header file that checks both the source providing the > function as well as places that call the function. That is, adding prototypes > in the function definition file purely for the purposes of avoiding missing > prototype warnings is missing the real usefulness behind the warning and giving > a false sense of security. (You'd be better off just taking > -Wmissing-prototypes out of your options to avoid those particular warnings.) > The prototypes need to be added to a header file, not the functions' own source. > > Put another way, as a general goal I'd think we ought to be fixing the cause of > a warning to remove the warning, rather than doing things to "hide" or "mask" > the warning (which could be considered as kludges). Putting protoypes into the > function source file is clearly masking the deficiency that there is not a > header file with prototypes, rather than fixing the actual deficiency. While > there certainly are times when addressing the root cause of a warning is not > possible, this does not seem to be one where it is appropriate. Probably > something like sys/_syscall.h (or some such name) should be created and used. > We should be cleaning up bad practice when it exists, not furthering it. So, > definitely a good thing to get rid of the warnings, but there is a much better > approach to take in this case. > > Corrina or Jeff, any suggestions for a good place for syscall prototypes? (My > first thought was sys/syscalls.h, but the Linux syscall(2) manpage mentions that > related to syscall() and "For SYS_xxx definitions." Perhaps it would be OK, but > perhaps not, too, which is why I ended up suggesting _syscall.h.) Does someone > know about a precedent in BSD or the like? > I agree with you, one of my intentions was precisely to get knowledgeable feedback because this patch indeed looks a little bit like a kludge :) I've noticed that the prototypes are conditionally defined in newlib/libc/include/sys/unistd.h under #ifdef _COMPILING_NEWLIB but I'm not familiar enough with newlib build system to know if this is the file to include or not. In particular, as I said before, the warnings appear when building for Aarch64 and not for Arm, so different code paths are used at least by these two targets. > Craig