This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Function pointer casts and warnings
- To: Dalibor Topic <topic at mpi-sb dot mpg dot de>
- Subject: Re: Function pointer casts and warnings
- From: Andreas Schwab <schwab at suse dot de>
- Date: Mon, 3 Jul 2000 15:52:03 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <Pine.GSO.4.10.10007031323520.11611-100000@orion>
Dalibor Topic <topic@mpi-sb.mpg.de> writes:
|> While casting function pointer types around is always safe, using cast
|> function pointers is not always safe. A compiler should know the type of
|> f at compile time, and it should be able to recognize the cast to a
|> different type (void (*) (void)) at compile time. Then the compiler should
|> detect that the cast function is called.
Did I understand you correctly that you have solved the halting problem?
|> Knowing that a function of some type is invoked with a wrong type, the
|> compiler could generate a warning.
It is impossible for the compiler to determine the dynamic type of an
expression in general, for the same reason why dynamic_cast<> requires
runtime support in C++.
|> In my first post, I had the example of a callback function test. The
|> compiler could detect that the function pointer f is cast to another
|> function pointer type before it is passed to the test function. It could
|> compare the cast type with the original type and detect that the
|> original function type expects a different set of arguments.
Your example may be able to be detected as a special case, but that does
not occur to me as a very typical one. For example, move the test
function to a different module and you are lost.
Andreas.
--
Andreas Schwab "And now for something
SuSE Labs completely different."
Andreas.Schwab@suse.de
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg