Non-standard C libraries ANSI

11

I am aware that, a C program in the ANSI standard can be compiled in both Windows on both Linux.

But when it comes to using sockets ? Is this not part of the ANSI C pattern? Because when I use sockets in Windows, I have to use a library called "Winsock.h" , on Linux, that library does not exist, and it uses another library called "socket.h" . In this case, a program in Windows that uses the "Winsock.h" library will give error when compiled in a Linux, and vise versa. However, Sockets are not in the default?

Another thing is the fork() function, this function exists only in Linux to do threads, I believe. So this function, which is non-existent in Windows, is out of the standard ANSI C ?

    
asked by anonymous 12.08.2015 / 14:54

1 answer

9

You're right. The sockets libraries are not part of ANSI. This standard only defines over the language all that is considered the standard language library which has only very basic operations, to do the minimum necessary and do not usually get involved with the operating system other than in very simple and standardized things like access to the terminal and files, for example.

Even this access to the operating system is limited. When you want more sophisticated access you need non-standard libraries that may or may not be available to multiple compilers, operating systems, or even processors.

The same goes for functions that handle processes like fork() .

In these cases there are usually libraries that abstract the operating system. That is, they internally know how to work with each operating system where it will be used but externally it works the same way.

Examples:

All of these work at least with Windows sockets and POSIX sockets.

Everyone allows you to work with threads on both POSIX and Windows systems. There is also a port of the pThreads library , which is POSIX, for WIndows.

    
12.08.2015 / 15:13