Monday, May 24, 2010

Can there be a multiple main function in one c++ or c program?

Any windows application has only single entry point named "main" for console application or "WinMain" for Windows application. Maybe you need multithreading to start simultaneously multiple functions? I mean something like this:





DWORD WINAPI _Thread1(LPVOID pParam)


{


//do something


return 0;


}





DWORD WINAPI _Thread2(LPVOID pParam)


{


//do something


return 0;


}





void main(void)


{


HANDLE hThreads[2];


hThreads[0] = CreateThread(NULL, 0, _Thread1, NULL, 0, NULL);


hThreads[1] = CreateThread(NULL, 0, _Thread2, NULL, 0, NULL);


WaitForMultipleObjects(2, hThreads, TRUE, INFINITE);


}

Can there be a multiple main function in one c++ or c program?
no!
Reply:you can create multiple functions. However there can only be one Main function
Reply:Main function is the part from where the compiler begins to read the program. Just like a book cannot have two beginnings, a C/C++ program cannot also have two main functions.
Reply:nope!
Reply:No can do...


No comments:

Post a Comment