Why is Linux not written in C++?

Why is Linux not written in C++?

I bet it would be much more readable and flexible if they used OOP.

Other urls found in this thread:

habrahabr.ru/post/263547/
cs.rit.edu/~ats/books/ooc.pdf
kernel.org/doc/Documentation/CodingStyle
harmful.cat-v.org/software/c /linus
warp.povusers.org/OpenLetters/ResponseToTorvalds.html
github.com/FFmpeg/FFmpeg/blob/master/ffplay.c
reddit.com/r/programming/comments/3qtkce/a_sad_story_about_get_temporary_buffer/
gcc.gnu.org/bugzilla/show_bug.cgi?id=61904
stackoverflow.com/questions/25025095/incorrect-stack-red-zoning-on-x86-64-code-generation
gcc.gnu.org/bugzilla/show_bug.cgi?id=27234#c10
github.com/systemd/
twitter.com/SFWRedditVideos

OOP isn't appropriate for performance-critical applications since it doesn't translate well to machine code.

I wish there were namespaces in C ;~;

They do use OOP, they just don't use the polymorphic, garbage-collected system that Java uses that people associate with the word "OOP".

C++ is unnecessary because many of its conveniences aren't usable in a non-hosted environment.

could I get an example of this OOP in C?

literally the kernel itself.

so you got nothing

habrahabr.ru/post/263547/

OOP IN LOO

cs.rit.edu/~ats/books/ooc.pdf

What I see most of the time is basically something like

typedef struct {
...
} someclass_t;

void someclass_method ( someclass_t *object, ... )
{
...
}


As long as you are disciplined with your naming schemes etc, there's really nothing you can't do. You can also put function pointers right into the struct like , but that has only disadvantages imo, makes very little sense to me.

so the use of handles I see all the time in apis are what you are talking about?

"literally just open the kernel source"

Jesus Christ, user, do I have to spell it out for ya?

Dumb teenager:

kernel.org/doc/Documentation/CodingStyle

This is all you need to know. Also see this:

harmful.cat-v.org/software/c /linus

do you really think you are so cool that you can read the design patterns of a piece of software with over 15+ million SLOC in five minutes?

VxWorks is written in C++ and is able to meet performance and reliability requirements that are nearly unachievable in Linux.

no, but I don't believe in handing out 100% complete answers on a silver platter for the zero effort of the requester.


...that's what StackOverflow is for.

1. C++ doesn't force OOP
2. C++ offers much more than OOP
3. not all forms of OOP imply performance penalty
4. stop being misinformed

>C++ is unnecessary because many of its conveniences aren't usable in a non-hosted environment
How about even more of those that are usable?

Linus hates C++

>the only advantage of C++ is OOP and garbage collection, etc.
>hurr durr you can simply not use them
Might as well just use C then, which is what the Linux team are doing.

>harmful.cat-v.org/software/c /linus
warp.povusers.org/OpenLetters/ResponseToTorvalds.html

What does C++ offer that C doesn't that is actually useful for writing low-level software? Even C++ Hello World is horrendously bloated unless you stick to using the C libraries.

you seem to have no clue about c++ then
apparently gcc switched to c++ for absolutely no reason

C++ doesn't provide garbage collection.

>TRIGGERED

The first thing you do when you start writing low level C++ is forget about iostream.

templates, classes, namespaces, constexpr, better type safety, lambdas, user-defined literals, better enums, standard containers, standard algorithms, to name a few

>C++

None of that stuff is useful to actual programmers, just to undergrad CS students and corporate code monkeys. Also
>better type safety
>better enums
Lmao
>user-defined literals
Wut? C has that too.

Then why not write in C? What does C++ provide that's useful for low-level programming that you don't get with C?

Linux uses loads of awful cpp macros that would translate to more maintainable C++ templates.

just stop making a fool of yourself
read anything about C++ and then use it in real software before shitposting

see

Bait

So you concede that C++ has got nothing to offer to C programmers?

Some of Linux is C++...

What book is that?

>c++ is a pile of crap.

t. Theo de Raadt

code that is written in C ALWAYS is less readable than code written in C++

the only people who think otherwise don't understand C++

I still have to see a proof for the claim that OOP makes things more readable and flexible and increases productivity.

>code that is written in C ALWAYS is less readable than code written in C++
I think you meant "never more readable" - most of C code is also C++.

>With C++, it’s possible to make code that isn’t understandable by anyone, with C, this is very hard.

I reckon Michael Abrash does understand C++ (and C, and everything else) a bit better than you. ;^)

Because shit garbage collection
its important to manage memory allocation when you handle registers directly at the kernel level

>it's hard to make unreadable C code
take a look at this fucking mess I've had to try and read recently (this is from ffmpeg): github.com/FFmpeg/FFmpeg/blob/master/ffplay.c

see the VideoState struct that is defined on line 203? in C++ they could just declare a class that has all of that shit in it as instance variables, but no, this is C, so we'll just throw it all in a huge ass struct and then pass that around to a bunch of functions that, if called in the wrong order, will fail spectacularly.

not to mention trying to remember to free() shit after using it, in C++ at least you have smart pointers, in C you just have to remember yourself because it's """""""""simple"""""""""""

the thing is, keeping everything """""simple"""" like that doesn't scale well. which is why big C programs (like ffmpeg) are god damn unreadable and is one of the reasons why the only contributors to ffmpeg and other hugely important pieces of software are neckbeards who have been with the project since the beginning.

I don't see how a class would improve the situation. If anything, it will just add more overhead (slowing down the implementation) and introduce meaningless boilerplate code.
>not to mention trying to remember to free() shit after using it
Oh, so you are just a scrub programmer. Git gud, I guess.

OpenSSL is another good example of the "strengths" of C.

linus does provide valid reasons though, for example:
>C++ compilers are not trustworthy
i can explain why this is true if people want.

do explain

explain

reddit.com/r/programming/comments/3qtkce/a_sad_story_about_get_temporary_buffer/
author name there, stepanov something

and c++ had none of that shit in the 90s when linux was created

>C++ compilers are not trustworthy
[non-zealot citation needed]

also, most often C compilers and C++ compilers are the same program, so...

wat

The C++ standard specifically allows for providing garbage collection.

C is outdated shit and anyone who still writes in it should kill themselves.

Software has bugs and for most Software the user encounters bugs, which then get fixed by the developer. For a lot of code extensive real-world usage is the only way to get stable, (relatively) bug-free code. Now consider GCC for x86 and Itanium. Some of GCC's code only runs when compiling for Itanium. These code paths are certainly not as tested as the x86 code paths. And they are significant enough to assume that there are bugs that only happen(ed) on Itanium. The same goes for x86.
Now when compiling kernel code there are often specific restrictions like nonstandard kernel-only ABI alterations etc. which get passed to the compiler via flags. So...when compiling with uncommon(but necessary for kernel development) flags you're much more likely to encounter bugs. Here's an example of such a bug:
gcc.gnu.org/bugzilla/show_bug.cgi?id=61904
explanations: stackoverflow.com/questions/25025095/incorrect-stack-red-zoning-on-x86-64-code-generation
>also, most often C compilers and C++ compilers are the same program, so...
yes, but compiling C++ code is a lot more complex, i. e. a lot of code in GCC is only used when compiling C++ and even then only in very specific cases.

>Why is Linux not written in C++?
To keep C++ programmers from working on the Kernel.

gcc and g++ are not the same program
clang and clang++ are not the same program
I'm pretty sure Intel maintains separate C and C++ compilers

What are you talking about?

That is an optional feature and compilers are not required to support it. Many don't.

wow i dont know shit about programming but literally he spazms about logic fallacies and then says this:
>By its very nature C encourages making unsafe, and often inefficient code.
>A prime example of the first is the standard C library function gets().
>This function is completely unsafe and it must never be used for anything.
>It reads characters from standard input into a fixed buffer, and it only stops when a newline character is found.
>If the buffer is not large enough, bad luck, you have a buffer overflow.
>There's absolutely no way of using gets() safely even if you wanted to (you have to use some other function).
He literally says that C is not safe because it has a function in it that NOBODY USES, that you cannot find in the linux kernel because its NOT USED.
Literally like saying that English is a very offensive language because it has swear words in it.

But now that GCC switched from C to C++ it will certainly become less buggy.

to add onto
"The fact is, the "official ABI" simply isn't appropriate. In fact, we
don't use the "official ABI" _anywhere_ in the kernel any more, since we
actually end up using other gcc calling conventions (ie regparm=3)." -Linus Torvalds
from: gcc.gnu.org/bugzilla/show_bug.cgi?id=27234#c10

nice meme

"Allows for" doesn't mean support for that feature is required in implementations.

I'm not a programmer but I would think it would have something to do with C being a lower level language, OOP probably isn't the best for designing a OS kernel, something like that

>I'm not a programmer
>here's my useless opinion
Thanks for your valuable contribution.

cmon the C standard library is complete shit, it's impressive how much subtly broken shit they came up with

because Torvalds doesn't like it.

harmful.cat-v.org/software/c /linus

gets() was deprecated in C99, and as of C11 is no longer a part of the specification. That is to say, gets() is not standard.

but every implementation still supports it because of legacy code right?

Not if you compile your code as C11.

>VxWorks is written in C++
You got a source on that?

C++ is as low level as C, and can do everything C does in OS development. OOP in C++ is often just a big syntactic sugar over structs, function pointers, and functions. If we have x of type Foo, and we call x.bar(2), we are actually calling a function Foo::bar(Foo *this, int arg); Virtual methods are resolved by having more or less invisible function pointers inside the fields of the struct.

Templates, constant expressions, and namespaces are all just compile time features that can make code easier to manage. They don't suddenly stop working in environments where you can't use the standard library or make assumptions about how memory allocation works.

Every implementation still supports it because the same compilers are used for C89 and C99, which require it. The world would be done a great service if all programs that use gets at least once in their codebases all suddenly broke simultaneously

Read any VxWorks manual. I've worked with VxWorks. You can use fucking cout and cin in your kernel extensions.

>A thing was deprecated in C99 and removed in C11

I am just starting to learn C and could someone explain to me what I'm supposed to know about these numbers?

there is no single "C" Language, the standard gets updated every few years. That said the majority of it is addtion, backwards combatibility with rather old code matters for C and C++

Alright. But what is the standard I should probably work with? What are the most used standards and for what reason are they used?

it's just different versions of the C standard user
there's also the C++ standard which is for C++
jsut use C for now

How do you solve polymorphism with this? I’m trying to ditch OOP but this is the thing I can’t figure out.

you have absolutely no idea what the fuck you're talking about, and you also do not program

I'm not particularly surprised at the contents of your post, just more the fact that it's even here

Could you faggots actually explain how he's wrong instead of masturbating at how right you are?

...

already done, see

Three common ways:
1) use void* and pass data + size_t everywhere
2) use macros to generate code for every type you use
3) reimplement dynamic dispatch yourself by adding type tags to the data passed around

Because OOP is a deprecated meme. No one in the Linux world uses c++ except for the systemd guy.

>C 95.4% Shell 1.2% Makefile 1.2% M4 1.0% Perl 0.6% Python 0.3% Other 0.3%

github.com/systemd/

I didn't really expect anything sane coming from someone who uses "meme" to describe everything.

>everything shall be assumed to be a pile of crap unless I have specifically deigned otherwise

t. Theo de Raadt

Why use C++ when you could not use C++?