- #1
RedX
- 970
- 3
What is the difference between ANSI C, ISO C, and POSIX?
I know that they refer to some type of standards, with ANSI being American and ISO being international, and that POSIX refers specifically to Unix-like OS's, which I assume means things like Linux and Mac (but what about UNIX: does UNIX-like mean UNIX?).
But what are they standards for? Are they standards for the name of functions, like saying print to screen should be called printf(), and the header file should be called stdio.h? Or are they standards for how functions should be implemented? malloc() for example is in stdlib.h, but wouldn't the function definition be different from OS to OS because each OS treats memory differently? So why isn't malloc() for Linux declared in something like unistd.h instead of stdlib.h? Similarly, why isn't malloc() for Windows in windows.h (I can't find a mac.h: is this because mac.h uses unistd.h?).
I've played around with some POSIX libraries: unistd.h, sys/types.h, sys/stat.h , and couldn't figure out what most of the functions did except tell me my user id, tell me the size of a page of memory, and make a directory, all things I could have done at the command prompt. Do the ISO and ANSI standards allow something like stdio.h to be implemented by calling functions from say unistd.h?
Also, the first person to write all these C libraries had to do so in Assembly right? And once written, you can use all these C functions instead of Assembly to rewrite all the C libraries, including the one you wrote earlier using Assembly? So if I were to look at GCC's source code for stdio.h (or I guess I should say stdio.a), would it be written in Assembly or C, and if written in C, would it include an older version of stdio.h as a preprocessor directive?
Also, would it be a mistake to write code using POSIX libraries, since Windows is the most popular OS so it is more lucrative to write using the windows library (windows.a)?
I know that they refer to some type of standards, with ANSI being American and ISO being international, and that POSIX refers specifically to Unix-like OS's, which I assume means things like Linux and Mac (but what about UNIX: does UNIX-like mean UNIX?).
But what are they standards for? Are they standards for the name of functions, like saying print to screen should be called printf(), and the header file should be called stdio.h? Or are they standards for how functions should be implemented? malloc() for example is in stdlib.h, but wouldn't the function definition be different from OS to OS because each OS treats memory differently? So why isn't malloc() for Linux declared in something like unistd.h instead of stdlib.h? Similarly, why isn't malloc() for Windows in windows.h (I can't find a mac.h: is this because mac.h uses unistd.h?).
I've played around with some POSIX libraries: unistd.h, sys/types.h, sys/stat.h , and couldn't figure out what most of the functions did except tell me my user id, tell me the size of a page of memory, and make a directory, all things I could have done at the command prompt. Do the ISO and ANSI standards allow something like stdio.h to be implemented by calling functions from say unistd.h?
Also, the first person to write all these C libraries had to do so in Assembly right? And once written, you can use all these C functions instead of Assembly to rewrite all the C libraries, including the one you wrote earlier using Assembly? So if I were to look at GCC's source code for stdio.h (or I guess I should say stdio.a), would it be written in Assembly or C, and if written in C, would it include an older version of stdio.h as a preprocessor directive?
Also, would it be a mistake to write code using POSIX libraries, since Windows is the most popular OS so it is more lucrative to write using the windows library (windows.a)?