Re: warn about function without & or arguments?

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

 



On 4/16/07, Matthew Woehlke <mw_triad@xxxxxxxxxxxxxxxxxxxxx> wrote:
Anyway, I read somewhere that omitting the '&' is deprecated/unsupported
for some language (i.e. might've been C++, or even Java) and/or standard
and/or compiler. Because I agree with the sentiment (it's nice for
readability also), I was hoping gcc could help enforce use of this syntax.

C++ requires the & on member function pointers, but not for regular
function pointers.  Last I checked, Java didn't have function
pointers, though I haven't followed it.

Warning for not using &, however, is impractical, even in C++.  If you
warn for taking the address of a regular function without using &,
then the usual "Hello World for C++ will give a warning:
#include <iostream>
int main() {
   std::cout << "Hello World!" << std::endl;
}
Because endl is actually a function
(http://www.roguewave.com/support/docs/sourcepro/edition9/html/stdlibref/basic-ostream.html#idx254).
It's done that way so that (stateless) manipulators can be defined
simply as normal functions
(http://www.roguewave.com/support/docs/sourcepro/edition9/html/stdlibref/basic-ostream.html#idx254)
.

~ Scott McMurray

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux