开发者

C code in Linux to C code in Windows

开发者 https://www.devze.com 2022-12-31 22:40 出处:网络
I\'m having a code written in C that works on Linux. I want this program to work in windows, A开发者_开发百科re there any differences that I have to make in the code ?

I'm having a code written in C that works on Linux. I want this program to work in windows, A开发者_开发百科re there any differences that I have to make in the code ?

It is a code for Server/Client communication using sockets taken from here : http://www.linuxhowtos.org/C_C++/socket.htm


You can compile your code under Cygwin or MINGW, both of which provide a certain degree of Linux-system-call-to-Windows-system-call-mapping, and you may avoid having to rewrite anything at all.


You will have to port the Linux code to Windows. There are differences between Linux and Windows sockets. You can check out this page for further information.

Also, this will help you with some of the porting.


Looking briefly at that article that you refer to reveals a few things that will likely need to change (assuming you are going to use something like Visual Studio to build it):

  • Replace read with recv
  • Replace write with send
  • Replace bzero with memset
  • Add calls to WSAStartup and WSAShutdown


Lots! Mark said it best it seems. recv and send still work however to a file descriptor. THe worst part is lack of GNU features like timeval struct without going through horrible windows includes.

0

精彩评论

暂无评论...
验证码 换一张
取 消