Programming in C - Differences between Linux and OSX

老子叫甜甜 提交于 2019-12-11 02:47:31

问题


Hello I'm looking into C Programming.

I'm wondering if there are differences between Linux and OSX in C? I know there are some between Windows and Linux/Unix (like getting a system timestamp). Are there any specific commands or techniques which won't work one of the two? Should "basic" programs run on both?

I'm aware that C isn't a cross compiling language but OSX and Linux are both Unix - aren't they?


回答1:


What changes is not the language itself, but the libraries (and related API calls). There is no difference between Mac OSX and Linux under this aspect, as long as you stick with standard POSIX calls. Both Linux and Mac OSX are POSIX-compliant systems.

Of course, when talking about proprietary Apple libraries, you can't expect to find them under Linux. But this is another problem. Same for Linux internals.

Note that we are talking about source compatibility, not binary compatibility. You won't have to modify your source code at all, but you will have to compile it for each platform separately.




回答2:


Linux includes quite a few extensions over the basic POSIX standard that both Linux and Darwin follow (Linux is "standard" in that it is exactly like Linux). As Stefano notes, in many cases this is fine, but if you have a program that was written for Linux without concern for portability ("runs on both Ubuntu and SuSE" is not "portability"), you should expect to see some different behaviors and missing extensions. For instance, mremap() and pipe2() are Linux-specific functions. SOCK_NONBLOCK is a Linux-specific flag to socket(), etc. The man pages will typically indicate when something is Linux-specific in the "Conforming To" section.



来源:https://stackoverflow.com/questions/19413115/programming-in-c-differences-between-linux-and-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!