This is a part of code i read in a standard book..


f()
{}
.
.
.

int *ip;
ip=((int *)f);

my question is..f gives d address of function..then wat is d need to typecast..??/

Recommended Answers

All 4 Replies

Not enough information, which is why you have been down-voted. There are a lot of "standard books" that I wouldn't use to wipe... you get my meaning. Even f() is, in today's standards, an invalid construct since the lack of a return type defaults to an integer, and there is no return value in the function. So, this is totally bogus and I have said enough. P.S. I teach advanced C and C++ programming to software engineers.

i thot tht ws quite implicit wat u said...
newez sry fr nt putting it correclty...
my doubt is simply whther is it necessary to perform d above typecast???

commented: Speak in full sentence English, please. That was part of the reason for the -1 before. -1

It depends upon what you want to do. As shown, it is pretty meaningless.

wat is d need to typecast..??/

First and foremost, function pointers and object pointers are incompatible with or without a cast. This cast is a very bad idea, and your book is likely written by an idiot unless it's showing how not to do things. To answer your question, the cast is required to compile because there's no implicit conversion from the function pointer type to int*.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.