On 16 Mar 2006 01:57:57 -0800, "Ramki" <writerama@gmail.com> wrote in
comp.lang.c++:
[color=blue]
> Hi,
> Your code should work.
> But, using reinterpret_cast<> is safe
>
> Checkout the following code snippet
>
> typedef int (*FP)(void);
> int add()
> {
> return 10;
> }
>
> main()[/color]
Your program is ill-formed, implicit int is no valid in C++, all
function definitions and declarations must specify a return type.
[color=blue]
> {
> FP funPtr;
> unsigned int num = reinterpret_cast<unsigned int>(add);
> funPtr = reinterpret_cast<FP>(num);
> printf("%d", funPtr());
> }
>
>
> Thanx,
> Rama[/color]
Your compiler is non conforming, or you are not invoking it in
conforming mode, if it accepts this program without issuing a
diagnostic for the implicit int in the definition of main().
It is also non-conforming if it accepts the application of
reinterpret_cast on a function pointer type to any scalar type. This
is just plain not valid C++.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html