C語言裡如何按需生成函式指標陣列?

時間 2021-06-01 04:04:19

1樓:暮無井見鈴

C++ 怎麼生成 4096 個函式?

參考這裡的巨集,編譯時生成這些函式是可行的。

C++ 的話用 index_sequence 模板就行。

2樓:VeroFess

手機回答…

我是這麼做的…shellcode + 彙編引擎 + mmap/VirtulAlloc

是不太安全

我乙個寫殼的管他安不安全

3樓:

gcc下:

#include

/** When use LAMBDA macro, arg_list should wrap with (),

* func_body should wrap with {}.

*/#define LAMBDA(ret_type, arg_list, func_body) ();

intarray[10

];inti;

for(i=

0;i<10;

++i)array[i

]=i;

printf

("%d\n"

,func

(array[5

],8));return0;

}湊合著用吧。。。

4樓:朱涵俊

你的意思是函式指標記錄某個引數嗎?

int foo(int x,int y)

int param[10];

int (*pfun)(int x,y)=foo;

(*pfun)(param[5],8);

簡單的事情為啥搞這麼複雜呢

5樓:機犬

放棄吧,我曾經腦子發熱給 C 寫過二進位制層面的閉包函式 github.com/yulon/clofn ,最後還是老老實實用 C++ 了(掩面逃

C 裡面最貼近的實現應該是用個結構記錄資料,做成該結構的陣列,執行函式的時候把結構作為引數傳進去(其實其他語言也大抵如此,只是語法糖的鹹甜區別了

6樓:zpan

typedef

struct

FooFoo

;struct

Foo;

Foofoo

(intx,

int(

*func

)(Foo*,

int))

;return

self;}

intcall

(Foo

*self

,intk)

intmy_foo

(Foo

*self

,intk)

intmain

(void

)printf

("%d\n"

,call(&

funlist[5

],8));return0;}

C 語言中指標陣列和陣列指標 函式指標 指向函式的指標等等該怎麼理解?

ga6840 direct declarator IDENTIFIER declarator direct declarator direct declarator assignment expr direct declarator declarator direct declarator poin...

C 中如何定義指向函式指標的指標?

zr scat 瀉藥先定義乙個函式指標 typedef void pfn void 再定義指向函式指標的指標 void print void pfn func print pfn ptr func 在c 11下,可以這麼偷懶獲得型別 1 include 23using namespace std 4...

C語言裡,main 函式中 return x和 exit x 到底有什麼區別

AutherM exit 是乙個 system call,表示要結束這個process,不管是parent 還是child return 是乙個函式的返回,不一定結束這個process,如果出現在被main呼叫的函式中,那就是返回到呼叫函式接下來的一條語句繼續執行 如果return 在main中,則...