5 ms·
> beyond what C/C++ has Whoa now, let's not go lumping C and C++ together! C++ has quite a heavier runtime to manage stuff like exceptions and RTTI! (though, t
by AceJohnny2 12y ago
> beyond what C/C++ has
Whoa now, let's not go lumping C and C++ together! C++ has quite a heavier runtime to manage stuff like exceptions and RTTI! (though, to be honest, I don't know what's a C++ program's runtime requirement if compiled with -fno-exceptions, -fno-rtti and the like)
- stormbrew 12y agoGenerally speaking the heavy part of both exceptions and rtti are in codegen (ie. the amount of code generated by the compiler), not in the 'runtime'. Exception jump tables and typeinfo objects are calculated as part of the compile and just referred to at run time. For example, this is the part of libsupc++ (effectively gnu's c++ "runtime") that deals with throwing: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_throw.cc https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-...
- kijiki 12y agoIf you disable rtti and exceptions, the only piece that needs runtime support is global constructors. I've done it in the past with linker tricks to generate an ELF section with the list of ctor addresses. The asm that calls main (which if you're rolling your own runtime, you probably wrote as well) just calls them all right before it calls main().
- pjmlp 12y agoC also has a runtime. It is called UNIX (POSIX).
- qznc 12y ago--freestanding
- kedean 12y agoI define a language without a runtime as one that can run on bare metal without restricting yourself to a subset of the language. To use C on bare metal, the only thing you can't use is the standard library, which is not a part of the language itself (its not in the grammar, you don't need to make sure to avoid certain keywords). More simply, any program written without using an import needs to work without an operating system under it. C++ requires runtime support because if you remove the underlying system, it becomes stunted. Keywords like 'new' and 'delete' stop working entirely, and so a program with no imports is not guaranteed to work. Any language with a GC falls under this, obviously. Rust, if I remember right, requires restricting yourself in order to do things like kernel writing.
- steveklabnik 12y ago> Rust, if I remember right, requires restricting yourself in order to do things like kernel writing. Nope, you just lose the standard library, and have to implement a few language intrinsics yourself.
- kedean 12y agoThat sounds kind of like what I mean. I consider it having a runtime if anything that can be used without importing the standard library won't work out of the box when you boot a machine to it.
- steveklabnik 12y agoWell, the 'standard library' is a bit of a flexible concept in Rust. We have 'libcore' and 'libstd'. core is what's still usable without any runtime support whatsoever, and std does. I mean, none of Rust's _features_ don't work without runtime support, but libraries that need tasks (threads) and task unwinding require the runtime. Those are all library features not language features.
- kedean 12y agoAh ok, interesting. I've been contemplating converting my toy kernel (which doesn't do all that much yet) into Rust, since it doesn't use a GC for everything, could be fun.
- steveklabnik 12y agoThere's several kernel projects already, you'd have a small community to talk to :) #rust-osdev on Mozilla's IRC is where they hang out.
- pjmlp 12y agoHow do you use ANSI C on bare hardware without help from Assembly (thus a mini-runtime) or language extensions? For the purposes of interrupt handling, IO ports (not all systems have memory mapped IO) and register access.
- the_why_of_y 12y agoFor example UNIX effectively provides a certain kind of memory safety to C programs, by isolating them via VM hardware from other C programs and their memory management bugs, which is quite important in practice... calling that a language "runtime" seems appropriate, especially since there are OS architectures that don't even require VM hardware for isolation (Singularity).