Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is Rust entirely independent of other languages and OSs like C is, or is it not?
Is Rust entirely independent of the OS and C?
Rust normally relies on the host system to support things like I/O. But it can be independent.
For OS development, you would use no_std: an environment for Rust without host support. This environment includes the core library (a subset of the std library) with no threads, no dynamic memory, no I/O. Implementing those would be part of developing the OS.
In C, there are a few constraints you should respect, such as not using any concurrency, limiting the use of the standard library, and such.
Not exactly. In freestanding C, there are a few standard library facilities that are guaranteed to be available.
Further, whether there may be several threads of execution is implementation-defined. When developing the usual OS with SMP etc, you will need a freestanding implementation with such support.
In Rust however, I have found that you should explicitly specify certain parts of your code to use C's linking implementation rather than Rust's, and taking many more aspects of your programming behaviour into consideration.
Not exactly either. One can program an operating system using only Rust's ABI to interface with assembly files and other bits. The problem is that such ABI is not going to be stable for the foreseeable future. Therefore, if you are willing to follow the changes, you could do it. But it is simpler to use C's instead.
Another possibility to avoid dealing with an ABI is trying to do everything with inline assembly instead.
So my question is, is Rust entirely independent of other languages and OSs like C is, or is it not?
Both can be, for freestanding purposes.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
Let us suppose that my computer does not have any operating system.
Is it possible to write a C program for running on this computer?
I think that it is possible to do that, but I'm not sure.
If this is possible, how can we do that?
This is why the standard defines "freestanding" implementations. Such implementations may be used to target hardware without any sort of OS or much of any support, really. You would need an implementation that supported your particular hardware enviorment (whether that is an embedded system of some kind, or some other bare-bones hardware). With that in mind, there are several important things to understand about freestanding implementations:
The way that program/system startup and termination happens is completely implementation defined. The might be a main that is called with some implementation-specific arguments, or there might be some other entry point(s) defined. Termination may not even be possible.
The standard library might be partly or even mostly missing -- there are only a few header files that a freestanding implementaion must support to be conforming (things like stdarg.h stdint.h, stdboolh. limits.h), so there might be no standard way of doing I/O or managing memory, for example.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm currently writing a text-based adventure game and I have a lifetime counter. I wanted to know if it would be possible to increment the lifetime counter upon starting the game without using a file?
I am using Windows 10 x64.
This is operating system specific, since while the C11 draft standard n1570 does mention files (in section §7.21) it does not mention other ways of persisting data.
You might consider using some database, e.g. the sqlite library or PostGreSQL or MongoDB. It might be overkill.
You could consider keeping persistent data (like suggested in this draft report, or coded in C++ in the RefPerSys software) in some textual format such as JSON. Concepts and terminology from garbage collection could be relevant (e.g. Cheney's algorithm). Read at least the old Uniprocessor Garbage Collection Techniques paper for terminology.
You might be interested by web services, using libcurl and/or libonion and/or Wt. Before that, read documentation related to HTTP. You might consider using JSONRPC or SWIG.
On Linux you might consider using shared memory or other ways of interprocess communication with several cooperating processes, see shm_overview(7), sem_overview(7), fifo(7), unix(7), poll(2) and other syscalls(2) (and atexit(3)). Read then Advanced Linux Programming
On Windows you need to read the documentation of the WinAPI.
You could be interested by the POSIX standard and by cross-platform libraries like GTK or libSDL. Both are often used in game software.
Notice that SBCL has some persistence machinery (see also this). You might take inspiration from its save-lisp-and-die primitive. You could also write parts of your game in Ocaml and take advantage of Ocaml's Marshal module. You could embed Python (or GNU guile, or Lua) in your game software and use its persistence features. Even if you don't code in SBCL or Ocaml, you could take inspiration from their runtime C code.
I'm currently writing a text-based adventure game and I have a lifetime counter.
Then look also (for inspiration) inside the source code of existing games on github.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I was looking around bored for stuff to do, then I stumbled across a guide on making your own simple C & Assembly command line operating system.
Im just wondering, is it just major operating system that use things like C or can an operating system be created in other languages, like android with java.
The lowest level of an operating system is the kernel, it runs on the CPU, so the languages used can't depend on virtual machines or interpreters. Compilers create machine code from the language, and generally package the output in modules with well defined formats. Those modules can be used to create libraries, applications, or an operating system kernel. You need a language that lets you specify the module contents with a fair amount of control, a language like C is fairly easy, a language like C++ makes it much harder, so is not used for the low level of an operating system.
At the lowest level, you need complete control over the output, because it has to match the hardware, not a module format, so you use assembly language for that.
Above the kernel, there's a lot of stuff that uses higher level interfaces, so doesn't need to be a specific binary module, and can use an interpreter or virtual machine. Those levels can be in Java like Android is.
The original MacOS was written in a version of Pascal. Some IBM mainframe OSes used PL/1. Those are no longer popular, but both compiled into modules like C does.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been developing for Windows for a long time, mainly WinApi (and .Net).
I'v started learning basic Linux, and I have some questions regarding the differences:
In Windows I have barely used the C Standard library.
If I needed an API, I would search MSDN and find the appropriate library\function.
From what it seems like, in Linux the C Standard library is EVERYTHING.
All the code samples I have seen used the standard library (Instead of using some Linux internal functions, like a Linux "CreateFile").
Is this really how writing "proper" linux code is done ? Using the C standard library ?
If I wish to read a file, or allocate memory are fopen\malloc the way to go ?
If the answer to my first question is yes (And I guess it will be)
The C standard library is POWERLESS compared to the powerful WinApi.
Lets say I wish to get a list of running process (CreateToolhelp32Snapshot) or create a thread or a process (CreateThread\CreateProcess), How should I do that in Linux ?
Documentation.
In Windows, all I need can be found in MSDN.
If I have a "how do I do" question (Like the questions above) where should I go ?
Where is my main source of documentation.
Thanks a lot,
Michael.
Perhaps you've forgotten that the Standard C Library isn't environment-specific, it specifies least-common-denominator functionality among all systems that can run C programs, and C runs on systems that don't even have processes.
If you want an API that provides consistent common GUI/multithread/etc. APIs, pick a likely-looking GUI/multithread/etc. API. You might start with Qt, it's quite comprehensive and produces good-looking, near-native UIs on a host of systems.
It's not generally considered polite to point this out, but most questions that get asked publicly are asked by people who lack the discipline to do even simple research. Once people can do that, they don't need to ask very many, and that's why what you see is so ... trivial. You're past that. For more options, you could start here.
For more general-purpose tools, the top hit on a search for important linux tools might be helpful.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Let’s assume that I wrote a primitive bootloader using assembly language. The computer is still on real mode. Now I want to write a primitive kernel and shell using C language.
Questions:
1.Do I need to write a C Language compiler in assembly for this new OS or can I use a C compiler running on a different OS? I guess it could be both!
2.If I use a C compiler from a different OS, functions like printf () can be compiled to target the BIOS’s functions instead of the OS’s API to avoid dependencies?
3.If my bootloader switch the computer into protected mode the kernel will need to implement the equivalent to the BIOS functions?
4.Assuming a YES to question 3: If I use a C compiler from a different OS what is required to make it target the new OS kernel functions? Rewriting the headers files?
(EDIT) PD: These are theoretical questions. I don’t need specific details about the actual implementation. I just want to validate the concepts. Don’t feel obligated to answer all of them!
You can do either. I would strongly recommend to just use a standard compiler though. Writing a good compiler is very complex and time consuming.
As long as you do not have an implementation of the standard library just don't use it. You can tell C-compilers to assume that there is no standard library and write your own printf-like functions.
You lose access to the BIOS functions in real mode. If you need them you do need to reimplement them.
Not much change is required actually. Executables are incomplete and require to be linked against something that implements the used standard library functions and whatever other libraries used. All you need to do is link the executable against a (possible self-written) library that somehow implements the required functions.