How does dereferencing of a function pointer happen?

前端 未结 5 930
忘掉有多难
忘掉有多难 2020-11-22 07:58

Why and how does dereferencing a function pointer just \"do nothing\"?

This is what I am talking about:

#include

void hello() { print         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 08:52

    Put yourself in the shoes of the compiler writer. A function pointer has a well defined meaning, it is a pointer to a blob of bytes that represent machine code.

    What do you do when the programmer dereferences a function pointer? Do you take the first (or 8) bytes of the machine code and reinterpret that as a pointer? Odds are about 2 billion to one that this won't work. Do you declare UB? Plenty of that going around already. Or do you just ignore the attempt? You know the answer.

提交回复
热议问题