edisonwsk / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

gcc "strict-prototypes" warning when including profile.h in C code #702

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. gcc  -Wstrict-prototypes -o /dev/null -c src/gperftools/profile.h

What is the expected output? What do you see instead?

Several undesirable warnings are from any non-C++ code that includes that 
header:

  gperftools/profiler.h:135: warning: function declaration isn't a prototype
  gperftools/profiler.h:140: warning: function declaration isn't a prototype
  gperftools/profiler.h:146: warning: function declaration isn't a prototype
  gperftools/profiler.h:147: warning: function declaration isn't a prototype
  gperftools/profiler.h:150: warning: function declaration isn't a prototype
  gperftools/profiler.h:154: warning: function declaration isn't a prototype

What version of the product are you using? On what operating system?

gcc 4.4.6 on Centos 6.2 (yeah, I know...)

Please provide any additional information below.

The problem is pretty simple.  Ancient C code allowed declarations without 
argument prototypes, i.e.

  int foo();

For compatibility this is still accepted.  If you want to declare a function 
with zero prototypes the correct way to do it is:

   int foo(void);

C++ also accepts this syntax, but it's not needed there.

Normally compilers still accept the old-style entries, but with sufficient 
warning flags gcc will complain about them.  It is good for header files to 
have the explicit "void" argument so all compilers are kept happy.

I'm attaching a simple patch to add the "void" parameter to that file.  I 
haven't checked if other headers have the same problem (I'm just using the 
profiler at the moment)

Original issue reported on code.google.com by mitchbl...@gmail.com on 30 Jul 2015 at 12:58

Attachments:

GoogleCodeExporter commented 9 years ago
Applied. Thanks a lot.

Original comment by alkondratenko on 1 Aug 2015 at 6:33