![]() Use a library which hides from us the fundamental differences between system API. Yes, sometimes preprocessor branch is an absolute saviour, but we should never overuse them - it's one of those things where we need to keep the balance. And it's more likely that each modification may break something else where we expect it the least. When all functions in our code have multiple #ifdef branches inside, the code becomes too hard to read and maintain. The main problem with this approach is that the code looks a little bit ugly. Use #if preprocessor branches in our code so that the compiler uses the appropriate logic for each OS. What if we want our app to run on embedded systems with limited hardware resources (CPU, memory)? Again, we need C. What if we need to build our program logic around several low-level C libraries? Although we can write the necessary library bindings for another language by ourselves, but instead we can just use C. What if we want to write a high-performance server software such as nginx? We absolutely need C. Even so, it's not the right solution for all possible scenarios. ![]() Switch to a different language (Go, Python, Java, etc.) which provides us with (almost) complete cross-platform system library. For example, if we want our app to run on Linux and Windows, then we'd need to write 2 different programs in C. One of the most inconvenient things in C programming is the requirement to support multiple OS because each OS has a different system API. Main Problems of Programming for Multiple OSĮxecuting Other Programs and Reading Their Output I do it with the hope that this tutorial will be useful, helping you to learn the system programming or perhaps to port an existing app from one OS to another. I've been writing cross-platform software in C for a long time already, and I want to share my experience with the others. We'll discuss the differences between the system API and how to create a cross-platform programming interface that hides all those differences from the user. I split the difficult stuff into parts so the code samples here shouldn't be overwhelming for those who has just started to program in C. We're going to write our own small helper functions on top of low-level userspace system API and use them so that our main code can run on any OS without modifications. In this tutorial we'll learn how to write cross-platform code in C using the system functions on popular OS (Windows, Linux/Android, macOS & FreeBSD): file management functions and file I/O, console I/O, pipes (unnamed), execution of the new processes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |