c++/7089: reinterpret_cast forbids cast void* to function pointer

rdabrowa@poczta.onet.pl rdabrowa@poczta.onet.pl
Thu Jun 20 13:35:00 GMT 2002


>Number:         7089
>Category:       c++
>Synopsis:       reinterpret_cast forbids cast void* to function pointer
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 20 12:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Rafal Dabrowa
>Release:        vary (2.96, 3.1)
>Organization:
>Environment:

>Description:
Compiler does not allow to cast pointer to object to pointer to function and vice versa, using reinterpret_cast operator. ISO forbids such operation for all other casts, but NOT for reinterpret_cast.
>How-To-Repeat:
Compile the following function:

void f(void *pv)
{
    void (*pf)() = reinterpret_cast<void(*)()>(pv);
}

The following error message appears:

  cast1.cc: In function `void f(void*)':
  cast1.cc:4: ISO C++ forbids casting between pointer-to-function and pointer-to-object
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list