我真的很討厭不得不在這裏提問。但我一直在尋找some of the other posts,像這樣的解決方案似乎並不奏效。它可能是我對語法的誤解。Dlsym:投射到不同大小的整數的指針
我正在改進我的一些舊代碼。問題中的函數循環遍歷一些加載的模塊並運行一個函數。當我在x86上時,這段代碼工作得非常好,但跳到64位正在搞砸了一切。
int FindCmd(ArgS *Args)
{
/* We need to check our loaded modules for the appropriate command. */
int found = 0;
ModS *Current;
for(Current = Modules; Current != NULL; Current = Current->Next)
{ /* Cycle through the modules. */
int (*OnConsoleCmd)(RootS *IRC, ArgS *Args, McapiS *Mcapi);
/* The below statement is the problem. */
OnConsoleCmd = (int (*)(RootS *, ArgS *, McapiS *))dlsym(Current->Handle, "OnConsoleCmd");
/* The above statement is the problem. */
if(OnConsoleCmd != NULL)
{
if(OnConsoleCmd(IRC, Args, Mcapi) != 0) /* Run command. */
found++;
}
}
return found;
}
我得到以下警告:
exec/src/input.c:98:18: warning: cast to pointer from integer of different size
,當然還有我的程序段錯誤。我知道這只是一個鑄造問題,但我不知道一個簡單便攜的解決方案。如果您需要更多信息,請告訴我。謝謝。
你不應該討厭在這裏提問,這在很大程度上是本網站的目的。 – dreamlax
@dreamlax:憎恨不得不去討厭。恨不得不意味着你對沒有經驗的建設性不滿。討厭意味着你不願意尋求你實際需要改進的幫助。 –