cannot convert `int (*)()' to `void*' in initialization - should not be an error

Gabriel Dos Reis Gabriel.Dos-Reis@cmla.ens-cachan.fr
Thu May 31 12:54:00 GMT 2001


Carlo Wood <carlo@alinoe.com> writes:

| On Thu, May 31, 2001 at 10:18:27AM -0300, Alexandre Oliva wrote:
| > They were in error.  GCC 3.0 is correct.  C++ doesn't allow implicit
| > conversion from function types to void*.
| 
| I noticed this too (and had to add a cast).  What is the reason
| that C++ doesn't allow this?

I don't think this is the right place to argue whether C++ should have
made it valid or not.  But the key data point is that `void*' is the
generic pointer to *object*. 

| I don't like casts, they normally lead to bugs later on.

But then, don't you think implicitly converting a pointer to function
to a generic pointer to object would lead to bugs?  C++ requires a
reinterpret_cast<> to make explicit that you're doing something
non-portable.  Note that the same requirement holds in C.

-- Gaby



More information about the Gcc-bugs mailing list