This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Function pointer casts and warnings


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]