[問題] __stdcall __cdecl
我要跑多執行緒 要有__stdcall的call convention:
unsigned __stdcall Foo(void* lp)
{
int *pInt = (int*)lp;
printf("%d\n", *pInt);
return 0;
}
這樣主程式才能使用:
int main(int argc, wchar_t* argv[])
{
HANDLE hThread;
unsigned threadID;
int* pInt = new int(10);
hThread = (HANDLE)_beginthreadex(NULL, 0, Foo, pInt, 0, &threadID);
printf("thread 1: %d\n", (const char*)hThread);
hThread = (HANDLE)_beginthreadex(NULL, 0, Foo, pInt, 0, &threadID);
printf("thread 2: %d\n", (const char*)hThread);
getchar();
delete pInt;
return 0;
}
我有兩個問題:
1. 是因為_beginthreadex參數有__stdcall 所以callee要加call convention
還是因為是呼叫OS的API所以才要加call convention呢?
2. 我查資料後 文件是說__cdecl是C和C++程式的預設呼叫方式
那一般我們在宣告函式的時候 都不寫call convention是因為他預設是__cdecl呼叫
還是其他原因呢??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.6.181
推
02/18 13:09, , 1F
02/18 13:09, 1F
→
02/18 13:10, , 2F
02/18 13:10, 2F
推
02/18 13:51, , 3F
02/18 13:51, 3F
→
02/18 13:51, , 4F
02/18 13:51, 4F
推
02/18 15:20, , 5F
02/18 15:20, 5F
→
02/18 15:44, , 6F
02/18 15:44, 6F
→
02/18 15:45, , 7F
02/18 15:45, 7F
→
02/18 15:45, , 8F
02/18 15:45, 8F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):