[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Why is Linux not written in C++? I bet it would be much more
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 86
Thread images: 6
File: linux-pengo-color.gif (15 KB, 427x194) Image search: [Google]
linux-pengo-color.gif
15 KB, 427x194
Why is Linux not written in C++?

I bet it would be much more readable and flexible if they used OOP.
>>
OOP isn't appropriate for performance-critical applications since it doesn't translate well to machine code.
>>
>>55395311
I wish there were namespaces in C ;~;
>>
>>55395267

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.
>>
>>55395586
could I get an example of this OOP in C?
>>
>>55395761
literally the kernel itself.
>>
>>55395845
so you got nothing
>>
>>55395761
https://habrahabr.ru/post/263547/
>>
OOP IN LOO
>>
>>55395761
https://www.cs.rit.edu/~ats/books/ooc.pdf
>>
>>55395761
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 >>55395877, but that has only disadvantages imo, makes very little sense to me.
>>
>>55395948
so the use of handles I see all the time in apis are what you are talking about?
>>
>>55395869
"literally just open the kernel source"

Jesus Christ, anon, do I have to spell it out for ya?
>>
>>55395869
Dumb teenager:

https://www.kernel.org/doc/Documentation/CodingStyle

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

http://harmful.cat-v.org/software/c++/linus
>>
>>55395972
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?
>>
>>55395311
VxWorks is written in C++ and is able to meet performance and reliability requirements that are nearly unachievable in Linux.
>>
>>55396010
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.
>>
>>55395311
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
>>
>>55395586
>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++
>>
>>55396135
>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.
>>
>>55395990
>http://harmful.cat-v.org/software/c++/linus
http://warp.povusers.org/OpenLetters/ResponseToTorvalds.html
>>
>>55396135
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.
>>
>>55396176
you seem to have no clue about c++ then
apparently gcc switched to c++ for absolutely no reason
>>
>>55396176
C++ doesn't provide garbage collection.
>>
File: 1310849798040.jpg (92 KB, 422x594) Image search: [Google]
1310849798040.jpg
92 KB, 422x594
>>55396193
>TRIGGERED
>>
>>55396216
The first thing you do when you start writing low level C++ is forget about iostream.
>>
>>55396216
templates, classes, namespaces, constexpr, better type safety, lambdas, user-defined literals, better enums, standard containers, standard algorithms, to name a few
>>
File: stl.jpg (99 KB, 600x800) Image search: [Google]
stl.jpg
99 KB, 600x800
>C++
>>
>>55396354
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.
>>
>>55396329
Then why not write in C? What does C++ provide that's useful for low-level programming that you don't get with C?
>>
>>55396408
Linux uses loads of awful cpp macros that would translate to more maintainable C++ templates.
>>
>>55396408
just stop making a fool of yourself
read anything about C++ and then use it in real software before shitposting
>>
>>55396453
see >>55396354
>>
>>55395267
Bait
>>
>>55396735
So you concede that C++ has got nothing to offer to C programmers?
>>
>>55395267
Some of Linux is C++...
>>
>>55396361
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++
>>
>>55395267
I still have to see a proof for the claim that OOP makes things more readable and flexible and increases productivity.
>>
>>55396871
>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++.
>>
>>55396871
>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
>>
>>55396918
>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): https://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.
>>
>>55397044
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.
>>
>>55397044
OpenSSL is another good example of the "strengths" of C.
>>
>>55396193
linus does provide valid reasons though, for example:
>C++ compilers are not trustworthy
i can explain why this is true if people want.
>>
>>55397262
do explain
>>
>>55397262
explain
>>
>>55396845
https://www.reddit.com/r/programming/comments/3qtkce/a_sad_story_about_get_temporary_buffer/
author name there, stepanov something
>>
>>55396354
and c++ had none of that shit in the 90s when linux was created
>>
>>55397262
>C++ compilers are not trustworthy
[non-zealot citation needed]

also, most often C compilers and C++ compilers are the same program, so...
>>
>>55397502
wat
>>
>>55396237
The C++ standard specifically allows for providing garbage collection.
>>
>>55395267
C is outdated shit and anyone who still writes in it should kill themselves.
>>
>>55397286
>>55397287
>>55397745
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:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61904
explanations: https://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.

>>55397745

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?

>>55398298

That is an optional feature and compilers are not required to support it. Many don't.
>>
File: UGLxbbG.png (562 KB, 632x738) Image search: [Google]
UGLxbbG.png
562 KB, 632x738
>>55396193
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.
>>
>>55398404
But now that GCC switched from C to C++ it will certainly become less buggy.
>>
to add onto
>>55398404
"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: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27234#c10
>>
>>55398404
nice meme
>>
>>55398298
"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
>>
File: 1417462823479.jpg (574 KB, 1698x1131) Image search: [Google]
1417462823479.jpg
574 KB, 1698x1131
>>55398992
>I'm not a programmer
>here's my useless opinion
Thanks for your valuable contribution.
>>
>>55398554
cmon the C standard library is complete shit, it's impressive how much subtly broken shit they came up with
>>
>>55395267
because Torvalds doesn't like it.

http://harmful.cat-v.org/software/c++/linus
>>
>>55398554

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.
>>
>>55399670
but every implementation still supports it because of legacy code right?
>>
>>55399981
Not if you compile your code as C11.
>>
>>55396015
>VxWorks is written in C++
You got a source on that?
>>
>>55398992

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.

>>55399981

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

>>55400100

Read any VxWorks manual. I've worked with VxWorks. You can use fucking cout and cin in your kernel extensions.
>>
>>55399670
>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?
>>
>>55400972
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++
>>
>>55401223
Alright. But what is the standard I should probably work with? What are the most used standards and for what reason are they used?
>>
>>55401245
it's just different versions of the C standard anon
there's also the C++ standard which is for C++
jsut use C for now
>>
>>55395948
How do you solve polymorphism with this? I’m trying to ditch OOP but this is the thing I can’t figure out.
>>
>>55398992
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
>>
>>55402180
>>55399288
Could you faggots actually explain how he's wrong instead of masturbating at how right you are?
>>
File: Q0vFcHd.png (152 KB, 1948x858) Image search: [Google]
Q0vFcHd.png
152 KB, 1948x858
>>
>>55402336
already done, see >>55400799
>>
>>55401997
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
>>
>>55395267
Because OOP is a deprecated meme. No one in the Linux world uses c++ except for the systemd guy.
>>
>>55403165

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

https://github.com/systemd/

I didn't really expect anything sane coming from someone who uses "meme" to describe everything.
>>
>>55396860
>everything shall be assumed to be a pile of crap unless I have specifically deigned otherwise

t. Theo de Raadt
>>
>>55395267
Why use C++ when you could not use C++?
Thread replies: 86
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.