close

http://www.newty.de/

=======================

動態指派函數去執行(這也是後來event hanlder都需要用此)

You can use them to replace switch/if-statements, to realize your own late-binding or to implement callbacks.

The calling convention tells the compiler things like how to pass the arguments or how to generate the name of

a function. Some examples for other calling conventions are __stdcall, __pascal and __fastcall. The calling

convention belongs to a function's signature: Thus functions and function pointers with different calling

convention are incompatible with each other! For Borland and Microsoft compilers you specify a specific

calling convention between the return type and the function's or function pointer's name.

=======================

結論就是

Callback 是pointer to function一種實作(透過pointer to function,可以達到late binding),

但是這個實在windows有用到event 發出時給系統處理,因此callback function位置與變數需要被全域化

(也可以理解成被OS觸發執行,而非程式設計者),這樣系統才不會被整個callback function要處理的內容給hold住。



Windows的event透過pointer to funtion實作的好處

在message queue中,只要透過message 對應到的function名稱,就可以執行。

而callback這個keywork,在windows程式設計中,如果用了這個keyword,系統會給函數一個全域的id(這是交給系統處理的),

這樣可以方便系統管理(這也意味者,如果有其他介面要跟call back function溝通,就需要有好的架構設計)。



-----


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 questioner 的頭像
    questioner

    questioner

    questioner 發表在 痞客邦 留言(0) 人氣()