Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Jacob: possible lcc64 CreateThread / WINAPI compiler bug

34 views
Skip to first unread message

John Conrad

unread,
Apr 30, 2013, 10:17:31 AM4/30/13
to
All code is compiled with -dll option (RIP-related addressing) with
latest version of lcc64

//This will crash:
//---------------------
#include <windows.h>
#include <stdio.h>

DWORD WINAPI thread(DWORD *p);

int main()
{
DWORD tid;
CloseHandle(CreateThread(NULL,0,thread,NULL,0,&tid));

loop:; Sleep(0); goto loop;
}

DWORD WINAPI thread(DWORD *p)
{
printf("Hello, Jacob, i'm cool thread, but i will crash\n");
}


//This will work:
//-------------------
#include <windows.h>
#include <stdio.h>

DWORD WINAPI thread(DWORD *p)
{
printf("Hello, Jacob, i'm cool thread and i will work, becouse i'm
located before CreateThread\n");
}

int main()
{
DWORD tid;
CloseHandle(CreateThread(NULL,0,thread,NULL,0,&tid));

loop:; Sleep(0); goto loop;
}



//And this will work (WINAPI removed):
//---------------------
#include <windows.h>
#include <stdio.h>

DWORD thread(DWORD *p); // WINAPI removed

int main()
{
DWORD tid;
CloseHandle(CreateThread(NULL,0,thread,NULL,0,&tid));

loop:; Sleep(0); goto loop;
}

DWORD WINAPI thread(DWORD *p)
{
printf("Hello, Jacob, i'm cool thread and located after CreateThread,
but i will work - WINAPI removed \n");
}


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

Is this a bug? Or how should i correctly declare the thread - with or
without WINAPI for 64 bit ?

jacob navia

unread,
Apr 30, 2013, 1:28:07 PM4/30/13
to
WINAPI means that the function is in a DLL and must use an indirect call.

It is the same as __declspec(DLLIMPORT), i.e. it declares a function
that is always extern in another DLL, and it is a function pointer.

Never use WINAPI for anything.


0 new messages