Topic: function ptr to object ptr


Author: jpotter@falcon.lhup.edu (John E. Potter)
Date: 1997/04/06
Raw View
void f ();
void* p(*reinterpret_cast<void**>(f));

As I read 5.2.10 [expr.reinterpret.cast], the above is ill-formed.  But it
seems that the following is valid.

void* p(*reinterpret_cast<void**>(reinterpret_cast<unsigned long>(f)));

Yes, it is implementation defined, and it does exactly what I want on the
implementation used.

Getting no answer from this group, I consulted my compilers.  Since most
of them do not support reinterpret_cast, I reverted to C style cast.  I
finally reserected USL CC 3.0 and got a diagnostic on the first form.
And, no diagnostic on the second form.  No newer implementation
complained about either.

Is my (and cfront) reading correct?  It seems unlikely that all of the
newer compilers would get it wrong when the first one got it right.

John
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]