Re: [問題] function程式碼不懂
※ 引述《j9353242 (阿鳥喂)》之銘言:
: 小弟我在寫程式時,遇到這樣的一個function
: Cpl64_SetCallback(int Handle, int EventType, void (_stdcall *fun)(int Handle,
: int EventType, void *Buffer, int Size))
: 想請問這function後面後面的部分void (_stdcall *fun)(int Handle,int EventType,
: void *Buffer, int Size)
: 這代表是另一個function?想請問這該怎麼令?
: 小弟真的是很新手,所以可能有些描述不清楚或不專業的地方,身邊又沒有人可以問
: 請多包涵
: 謝謝各位看完
要弄懂這個先回答以下(答不出來就跳到2):
1.
(a) char ptr; sizeof(ptr)=?
(b) char ptr[3]; sizeof(ptr)=?
(c) char ptr[3][4]; sizeof(ptr)=?
(d) char *ptr; sizeof(ptr)=?
(e) char *ptr[3]; sizeof(ptr)=?
(f) char *ptr[3][4]; sizeof(ptr)=?
(g) char (*ptr) sizeof(ptr)=?
(h) char (*ptr)[3] sizeof(ptr)=?
(i) char (*ptr)[3][4] sizeof(ptr)=?
(j) char ptr(int *a) sizeof(ptr)=?
(k) char ptr[100](int *a) sizeof(ptr)=?
(l) char *ptr(int *a) sizeof(ptr)=?
(m) char (*ptr)(int *a) sizeof(ptr)=?
(n) char ((*ptr)(int *a))(int *b) sizeof(ptr)=?
答不出來嗎?快點printf看看大小!!
2.不知道理由嗎?快這網頁:
http://programming.im.ncnu.edu.tw/Chapter12.htm
key: 必須遵守C程式語言對*()[]的優先權定義 看完後先做衣些練習
char *x; // x: a pointer to char
char x[3]; // x: an array[3] of char
char x(); // x: a function() returning char
char *x[3]; // x: an array[3] of pointer to char
char (*x)[3]; // x: a pointer to array[3] of char
char **x; // x: a pointer to pointer to char
char *x(); // x: a function() returning pointer to char
char *x()[3]; // x: a function() returning array[3] of pointer to char
char (*x[])(); // x: an array[] of pointer to function() returning char
char (*x())(); // x: a function() returning pointer to function() returning
char
char (*(*x)[])(int, int); // x: a pointer to array[] of pointer to
function(int,int) returning char
3.call reference到底要傳進啥?
int a; add(?a); => add(int ??a)
int a[3]; add(?a); => add(int ??a)
int a[3][4]; add(?a); => add(int ??a)
解答:
-解法1 a pointer to arry http://codepad.org/JKl47SG7
-解法2 arry[N] of pointer to [3][4][5]http://codepad.org/ICFCfBDw (個人認為..)
-解法3 a int pointer http://codepad.org/5A41K8ej
4.void (*ptr)(int *abc) 是啥呢?
先牛刀小試一下:
http://codepad.org/pDWnFvUj
你可以知道:
(1) ptr是一個void指標
(2) void pointer指向一個回傳值是void的 function(int *a)
(3) ptr後面的引數隨意
所以...你可以設計你的function 傳人的值是"一個pointer to function()"
http://codepad.org/zMdXoMxj
--
有錯請指正...剛好最近在看 T.T
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.8.99
→
05/16 22:18, , 1F
05/16 22:18, 1F
推
05/16 22:54, , 2F
05/16 22:54, 2F
好像滿好玩的...但..研究_cdecl _stdcall中...T.T
※ 編輯: kingofsdtw 來自: 122.117.8.99 (05/16 23:55)
推
05/17 13:45, , 3F
05/17 13:45, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):