Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming Operating Systems Software Technology Linux

C++ In The Linux kernel 850

An anonymous reader submits "A researcher at Reykjavik University Network Laboratory (netlab.ru.is) has just released a Linux patch allowing for complete kernel-level run-time support for C++ in the Linux kernel, including exceptions, dynamic type checking and global objects (with constructors and destructors) The implementation is based on the C++ ABI in GNU g++, but contains various kernel level optimizations, that reduces the cost of throwing exceptions by an order of magnitude, thus making C++ exceptions viable in several scenarios. Furthermore, the Linux module loader is extended to handle weak symbols in C++, so that dynamic type checking is reduced to a pointer comparison, in contrast to string comparison."
This discussion has been archived. No new comments can be posted.

C++ In The Linux kernel

Comments Filter:
  • by Anonymous Coward on Wednesday October 27, 2004 @05:54PM (#10647378)
    C++ in the Linux Kernel

    We have implemented a complete kernel level run-time support for C++ in the Linux kernel. In particular our run-time support enables the full use of C++ exceptions in the Linux kernel, but notably also includes support for global constructors and destructors, and dynamic type checking. Our kernel level support is based on open source commodity components, specifically the GNU gcc/g++ compiler and its exception implementation, the C++ ABI version independent standard interface.
    C++ runtime support for 2.6.6 (Last update 27 october 2004)
    C++ runtime support for 2.6.9 (Last update 27 october 2004)

    Using the C++ runtime support for Linux
    Installing the C++ runtime support for Linux

    The code is installed by applying a patch to the Linux kernel and enables the full use of C++ using the GNU g++ compiler. Programmers that have used C++ in Linux kernel modules have primarily been using classes and virtual functions, but not global constructors. dynamic type checking and exceptions. Using even this small part of C++ requires each programmer to write some supporting routines. Using the rest of C++ includes porting the C++ ABI that accompanies GNU g++ to the Linux kernel, and to enable global constructors and destructors.

    The implementation of the C++ ABI is based on the implementation provided with the source of the GNU g++ compiler. We modified it to run in kernel space, and performed optimizations that reduces the cost of exceptions and dynamic cast considerably. Our paper contains thorough explanations of these optimizations. The cost of throwing an exception one level on a 990 MHz Intel Pentium is around 12-13 micro seconds in the plain GNU g++ implementation, which we reduced to 2.1 micro seconds by modifying the runtime library, including unwinding the stack in one phase, and caching information on exception paths. In contrast the cost of a trivial printk operation -- printk("Error\n") -- is 18 micro seconds.

    In addition, we modified the linux kernel module loader to handle C++ weak symbols correctly. GNU g++ associates with each class a type information object that encodes the type of the class as a mangled string and puts a pointer to this object in the virtual table for the class. GNU g++ uses weak symbols to reduce the dynamic type checking to a pointer comparison, thus avoiding the more expensive string comparison. Each time a class, containing virtual functions, is used in a source file, GNU g++ generates the virtual table, type information object and type name string as weak symbols and the user space linker ensures that there is only one copy of this object, which renders the simple pointer comparison sufficient. However, the kernel module loader, which in the 2.6 versions of the kernel is exclusively in kernel space, does not handle these weak symbols correctly and always relocates references to weak symbols to the weak definition within each object file that is being loaded. Therefore multiple type information objects may exist for the same class and pointer comparison becomes insufficient when doing dynamic type check across kernel modules. To avoid this overhead we have modified the kernel module loader to handle these weak symbols; the first time a weak symbol is encountered it is added to the symbol map, and on subsequent encounters the relocation is done to the first symbol.

    Paper:
    Exceptional Kernel: Using C++ exceptions in the Linux kernel
    Halldor Isak Gylfason, Gisli Hjalmtysson
    Submitted for publication October 2004 abstract

    Please direct bug reports, questions and comments to {halldorisak at ru dot is}
  • by RAMMS+EIN ( 578166 ) on Wednesday October 27, 2004 @05:55PM (#10647392) Homepage Journal
    Linux doesn't want any C++, so as long as he's at the top, it likely won't get far. And I think that's good, given the state of C++ in gcc (hint: slow and memory-intensive compiles, generating subobtimal code).

    But I'll shut up. I've pretty much turned my back on C and C++ anyway.
  • Who cares? (Score:5, Informative)

    by Percy_Blakeney ( 542178 ) on Wednesday October 27, 2004 @05:57PM (#10647407) Homepage
    I really don't see the use in porting these features to the Linux kernel -- they'll never be used in any mainstream kernel release. Linus has stated many times that he doesn't particularly care for C++ in the kernel [tux.org]:

    In fact, in Linux we did try C++ once already, back in 1992.

    It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

    The fact is, C++ compilers are not trustworthy. They were even worse in 1992, but some fundamental facts haven't changed:

    * the whole C++ exception handling thing is fundamentally broken. It's _especially_ broken for kernels.
    * any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel.
    * you can write object-oriented code (useful for filesystems etc) in C, _without_ the crap that is C++.

    In general, I'd say that anybody who designs his kernel modules for C++ is either

    * (a) looking for problems
    * (b) a C++ bigot that can't see what he is writing is really just C anyway
    * (c) was given an assignment in CS class to do so.

    Feel free to make up (d).

  • Re:Progress (Score:4, Informative)

    by alienw ( 585907 ) <alienw,slashdot&gmail,com> on Wednesday October 27, 2004 @06:05PM (#10647488)
    Nothing will come out of it, for the simple reason that C++ does not belong in any kernel. In a kernel, all the code needs to be transparent, and you definitely don't want to hide implementation and the usual abstractions.

    The simple reason for that is that otherwise the kernel would be unpredictable. Let's say the error logging function used the string class (which likes to allocate memory behind your back). If the memory allocation function fails and tries to print an error message... you got yourself a kernel crash. This is why the kernel is significantly more difficult to program than, say, a word processor.
  • I take exception... (Score:5, Informative)

    by IceAgeComing ( 636874 ) on Wednesday October 27, 2004 @06:07PM (#10647511)

    I've only written one linux driver, so I'm no expert, but I can think of situations where exceptions can be helpful for device drivers.

    Take, for example, a game controller or other hardware device that can become unplugged at any moment. It's useful to have an elegant way of handling this uncommon occurrence.

    Exceptions are a useful way to separate uncommon sanity checks from the rest of your code, so you're not forced to use ugly nested conditionals.
  • Re:Yay! (Score:5, Informative)

    by apankrat ( 314147 ) on Wednesday October 27, 2004 @06:09PM (#10647532) Homepage
    It's not the slowliness, it's the obscuirty and the lack of control over the binary code size it introduces. Something as simple as 'a == b' may easily add few KB to the kernel.

    If you think it's OK, you obviously haven't been involved in kernel or embedded development. If you say one should be careful what features of C++ he uses and not to use this and that, I say one should learn proper C skills instead.

  • by Lally Singh ( 3427 ) on Wednesday October 27, 2004 @06:09PM (#10647534) Journal
    exceptions are a great way to structure your error handling.
    they're an in-language mechanism similar to signals, only that they don't have the brain-deadedness of them.

    Hell, just having smart pointers whose destructors are properly called on the stack unwind is enough.
  • Objective-C (Score:1, Informative)

    by Anonymous Coward on Wednesday October 27, 2004 @06:10PM (#10647540)
    Worse than C++.
    Objective-C is too dynamic, and all objects are heap objects.
  • by BCoates ( 512464 ) on Wednesday October 27, 2004 @06:12PM (#10647555)
    I think that's a bit backwards; ordinary user applications can just terminate ungracefully, and the kernel will clean up after them (close all open files, free memory, etc) if a section of kernel code runs into a problem, it has to roll back everything to a sane state before returning to the caller if there's going to be any hope for the entire kernel to keep going (without leaking). I believe right now the linux kernel mostly does this with an elaborate system of gotos and return value checking that's pretty much exactly what C++ stack-unwinding does, just by hand.
  • by Anonymous Coward on Wednesday October 27, 2004 @06:16PM (#10647599)
    RTFA. This is not about a compiler in the kernel, it's about using C++ instead of C.
  • by Lally Singh ( 3427 ) on Wednesday October 27, 2004 @06:16PM (#10647600) Journal
    Nope. It's a condition that the throwing code couldn't handle. Someone else can handle it.

    Classic example: a method calls another that calls another that calls openfile() for a temp file, which fails. the lower two methods don't care, and the toplevel one can give the user a proper error message and clean up.

    People wonder why software is so hard to test, does so poorly on error handling, yet complain whenever we add mechanisms to languages to help.
  • by cout ( 4249 ) <{curlypaul924} {at} {gmail.com}> on Wednesday October 27, 2004 @06:17PM (#10647609) Homepage
    Oh dear. Another person who thinks that exceptions should never be thrown.

    If exceptions were never meant to be thrown, they wouldn't be in the language. Exceptions are an abstraction for dealing with exceptional conditions -- conditions that do not normally occur, but can occur. At the expense of some additional complexity, they make error checking a little simpler and less bug-prone. When (not if -- assuming you are a believer in Murphy's law) those exceptional conditions occur, your program better be able to handle them correctly.

    You are right that some people do use exceptions when not appropriate. Exceptions are (generally) not appropriate for exiting loops, for example. But they are more than appropriate for out of memory conditions, out of disk space conditions, etc.

    The reason they are not viable performance-wise is not because they are too expensive to throw; it is because they are too expensive when they are never thrown at all. There's generally a 5-10% performance hit just from having code that might possibly throw an exception, depending on your compiler's implementation. The numbers on the netlab page are for throwing exceptions, unfortunately; I would be interested in seeing if they got a performance benefit when exceptions are not thrown. Guess I'll have to dig to find a copy of the paper.
  • That's bull... (Score:2, Informative)

    by MouseR ( 3264 ) on Wednesday October 27, 2004 @06:30PM (#10647713) Homepage
    thus making C++ exceptions viable in several scenarios

    By experience, C++ exceptions are the worse way of handling errors and leads to too many warp jumps that are difficult to track, trace and debug.

    C++ in a kernel is fine with me. But throwing exceptions in there is asking for trouble.
  • Re:Who cares? (Score:5, Informative)

    by AuMatar ( 183847 ) on Wednesday October 27, 2004 @06:36PM (#10647759)
    The first argument is easy- exceptions are a Bad Idea. Error codes are much cleaner and more logical. Even the few embedded projects I know that use C++ outlaw the use of exceptions in their code (generally templates as well, for emmory reasons).

    The second- C++ has hidden allocations all over. In C, its easy to find memory allocations. Grep for malloc (or kmalloc in the kernel). In C++, you have temporary objects being instantiated all over the place, automatic constructors/destructors being called, etc. Its nowhere near as open or easy to find (especially temporary object creation. If you don't think thats a problem- try putting a cout statement in a constructor, and write a function that takes an object as a parameter and returns that object. Count how many you see. Its more than 1.) Its not as clean. While this may be tolerated (although confusing) for an application, for a kernel its murder. Memory is tight, and mallocing will kill you performance wise if you need to grab a new free page. It may not even be possible to do if interrupts are locked. Its a hassle.

    In fact, a lot of embedded project don't even allow dynamic memory. I design printer firmware. We are not allowed to call malloc. All memory is tightly controlled by thesystem and is strictly deterministic to ensure we can always do a job. A large amount of object creation doesn't make sense in an embedded/kernel environment.

    Third- why not? There's places where its the best tool fro the job. Assembly gets a bad rap, really its a nice simple language. The real question is- what does C++ give you that C doesn't? Objects- C has them. Inheretance? Very rarely does it really benefit you, its usually used because "we're OO, we're supposed to use it". Templates? Ok, those can be useful for things like linked lists, although the STL goes way over the top with it. Exceptions? See above. The gains of C++ are minimal, the pain of it is large.
  • by Lally Singh ( 3427 ) on Wednesday October 27, 2004 @06:40PM (#10647818) Journal
    essentially a quote of linus's comments from the 1992 test. boo hoo, he tested a pre-standard language and a pre-standard compiler (which was honestly crap on C++ until very very recently).
  • Re:More Confusion (Score:2, Informative)

    by pyrrho ( 167252 ) on Wednesday October 27, 2004 @06:42PM (#10647837) Journal
    there can't be a distinction, C++ owes itself to an "improved C" mentality. C people can dissown C++ (except the parts that made it into ANSI C) but C++ people can't dissown C... and don't want to.
  • by Lally Singh ( 3427 ) on Wednesday October 27, 2004 @06:44PM (#10647857) Journal
    if it matters which part of the code had the error, then use separate try blocks for each part. In real life, most exception handling code DOESN'T care which function called it, or can tell from the exception type. As we've got more expressiveness than the value for ERRNO, we can do that here.
  • by Anonymous Coward on Wednesday October 27, 2004 @06:45PM (#10647868)
    You can use setjmp(), longjmp() with the same effect in C without the extra baggage that comes with C++ exceptions.
  • by noselasd ( 594905 ) on Wednesday October 27, 2004 @06:49PM (#10647910)
    Linux made his view on C++ in the kernel a while ago here [kerneltrap.org]
  • Re:Progress (Score:3, Informative)

    by 12357bd ( 686909 ) on Wednesday October 27, 2004 @06:56PM (#10647982)

    Yes, a kernel is more difficult than a word processor, but that doesn't mean that implementors must implement stupid C++ code.

    No, the problem is not if it's difficult or not, is the fact that C++ implies the existence of an intrinsic memory management behaviour (new/delete), that is not really compatible with the strict memory management a kernel must implement.

  • Reality check (Score:2, Informative)

    by pslam ( 97660 ) on Wednesday October 27, 2004 @06:57PM (#10647998) Homepage Journal
    Nothing will come out of it, for the simple reason that C++ does not belong in any kernel. In a kernel, all the code needs to be transparent, and you definitely don't want to hide implementation and the usual abstractions.

    The simple reason for that is that otherwise the kernel would be unpredictable. Let's say the error logging function used the string class (which likes to allocate memory behind your back). If the memory allocation function fails and tries to print an error message... you got yourself a kernel crash. This is why the kernel is significantly more difficult to program than, say, a word processor.

    Put the strawman away. You don't absolutely have to use all the features C++ gives you if they aren't right for you. Don't use exceptions or run-time typing in an environment where you don't need it, or don't know if it'll work. Personally I never use either because I strongly disagree with the code they generate. If you don't understand that skilled usage of C++ generates exactly the same code that the equivalent C would (except the C++ took less time to type and checked your syntax better), you don't understand the point of C++ whatsoever. It's just a glorified type checking macro expander. And there's no reason to use plain C when you've got that at your disposal.

    Now have a look at examples of kernels written in C++. One easy example: Red Hat eCos [sourceware.org]. Just saying that C++ doesn't do kernels well doesn't remove the fact that people do use it in kernels, it works very well, and there are many examples out there.

  • Re:Yay! (Score:5, Informative)

    by myg ( 705374 ) on Wednesday October 27, 2004 @07:06PM (#10648090)
    I'm an embedded developer. I've done some projects as C only and some as C++. With proper discipline C++ can actually generate smaller, more compact code than straight C. But getting the infrastructure done is a bit harder.

    In fact, eCos, a very nice (GPL) embedded operating system has its kernel written in C++. eCos performs well and is cleaner than a competing straight C RTOS which has to build its object system by hand (VxWorks' WIND kernel).

    The real difficulty in using C++ for embedded development comes from the toolchains themselvs. Frequently new processor architectures don't have very functional C++ back ends but C is somewhat stable.

    In fact, I worked on porting some C++ TV middleware to a specialized "media DSP processor." The GCC back-end for C was rock solid but C++ constructs would give me constant ICEs.

    C++ does fix some dumb things in C, but when it comes to shooting yourself in the foot, C++ is like an AK-47 while C is more like a .38 special.
  • Re:nice (Score:5, Informative)

    by myg ( 705374 ) on Wednesday October 27, 2004 @07:30PM (#10648334)
    The core of Windows is written mostly in C. The GDI was written in C++ and the chief Kernel architect of WinNT (David Cutler) continually jabbed the Graphics group on their choice of C++.

    I don't suspect you will be finding C++ in NTOSKRNL any time soon. I think Cutler would beat up anybody who tried.
  • by Anonymous Coward on Wednesday October 27, 2004 @07:42PM (#10648439)
    Haiku (formerly OpenBeOS) has had parts of the kernel in C++ since the beginning.

    Most notably the reimplementation of the Be File System. (Now OpenBFS)

    http://cvs.sourceforge.net/viewcvs.py/open-beos/ cu rrent/src/add-ons/kernel/file_systems/bfs/
    The filesystem is not slow at all. Actually the Haiku-people did some speed comparisons with Be's BFS and OpenBFS won.

    Other parts of the kernel is C++ as well. The device manager, an experimental vm..

    I've never really understood this anti-c++ in kernel thing.
  • by Beatlebum ( 213957 ) on Wednesday October 27, 2004 @07:50PM (#10648498)
    You're confusing exceptions with assertions. Exceptions can be used to elegantly handle boundary conditions. Assertions flag events that should never happen *if* the code logic is correct. Exceptions stay in both debug and release builds, assertions are not usually compiled into release binaries.
  • by arkanes ( 521690 ) <arkanes@NOSPAM.gmail.com> on Wednesday October 27, 2004 @08:14PM (#10648696) Homepage
    Exactly. Here's an example of poor use of exceptions:

    try {
    while (1) {
    read_from_file();
    }
    } catch (EOFException) {
    clean_up_file();
    }

    This is bad because you're using an exception to manage normal program flow. Here's a better use of exceptions:

    try {
    File f("myfile"); //file object manages state
    while (!f.eof()) {
    f.read();
    }
    } catch (FileOpenException) {
    //file object is cleaned up by it's
    //destructor, only thing we need to do is
    //alert user
    }

    This is a simplistic case, because you can just easily do this by checking error codes. It shows it's worth when you have, say, a dozen different files to open. You save a lot of if-checks, a lot of duplicate error handling (alerting the user and returning), and you don't have to worry about manually closing all the files which might be open, preventing resource leaks. If your exception system is properly designed, you don't lose any information, because stuff like the file you were trying to open is preserved with the exception information.
  • Re:Who cares? (Score:2, Informative)

    by s0lar ( 217978 ) on Wednesday October 27, 2004 @08:30PM (#10648827)
    > (a) looking for problems
    This is a boolshit argument - you get problems with C too. Big problems with "evil macros", memory leaks, resource dead locks, pointer arithmetic, stack corruption etc. It's a matter of expertise, regardless of the language.

    Sure, the C way seems transparent and obvious, but complex problems require more involved solutions. Solutions that abstract building blocks in order to manage this complexity. Abstraction mecanisms are much better with C++. The same goes for encapsulation - OO way provides several useful mechanisms than "static".

    > (b) a C++ bigot that can't see what he is writing is really just C anyway
    The point Stroustrup makes is that one can use a subset of C++. It's a valid thing. However, OO concepts are native to the language, so no function pointer assignments are required to implement abstraction. No "just return a handle" hacks are required to have encapsulation. Why not use a language that natively supports and checks for polymorphism, abstraction and encapsulation?

    Now, all of this is described much better in a "Conversation with Bjarne Stroustrup" by Bill Venners here:
    Part 1: The C++ Style Sweet Spot http://www.artima.com/intv/goldilocks.html [artima.com]
    Part 2: Modern C++ Style http://www.artima.com/intv/modern.html [artima.com]
    Part 3: Abstraction and Efficiency http://www.artima.com/intv/abstreffi.html [artima.com]
  • Re:Who cares? (Score:3, Informative)

    by Foolhardy ( 664051 ) <csmith32 AT gmail DOT com> on Wednesday October 27, 2004 @08:58PM (#10649001)
    Temporary objects. Compilers create temporary objects, especiall arounjd function calls/returns. These call the constructor, which may call malloc. The number of situations temporary objects can be made is actually failry high and very complex. If the language is creating objects you don't explicitly ask for and calling malloc off that, I count that as the language using memory. Its the fault of the language for creating the object.
    Don't use classes that call malloc on copy. This would be the library in which the class belong's fault. Either that or always pass by reference or pointer; no copy required. Use const if you don't want the value changed. This can be a rule for the project.
    Like I said- function pointers. Like this:
    You're right. I wasn't thinking about that. Still, you can't inline across function pointers. That could lead to bigger code if the function body uses less instructions than a function call.
    struct outer{
    int handle;
    }

    struct inner{
    int x,y;
    }

    int some_privlidged_func(outer *o){
    inner *in= (inner*)o->handle; //now just reference inner->x and inner->y
    }
    Ick, this assumes that sizeof(int) == sizeof(void *); that is a bad assumption for portable code. Also, you have a one member structure. A better idea would be an empty structure for outer; cast a pointer to outer to get inner.
    I guess this would work pretty good, although you would have to maintain functions to access any data inside of inner whereas you could get to it directly with public. That was my point, that public/private is more convenient than handles. It lets you concentrate more on important things rather than wasting time writing glue functions, as you must to access any properties of a handle.
    It gives them additional ways to break the rules. The more rules, the more people will want to break them, or just waste your time disagreeing with them. Its a social problem, not a technical one. And with larger teams, its a larger problem (with small teams the team probably made the rules themselves and hashed out differnces then). On a small 3-5 person project restricting features works. On large ones it just becomes a hassle. On very large ones with more than 1 gatekeeper to the code, it breaks down entirely (all you need is 1 lazy/disagreeing member with check in privlidges).
    Kernel code already has a million ways to do bad things. Having a different language won't make it much worse. Done properly, C++ can help you write better code that is MORE resilient to idiocy, not less, using namespaces, new types by overloading, smart/safe pointers, templates, member protection...
  • Re:Alright!! (Score:5, Informative)

    by Bloater ( 12932 ) on Wednesday October 27, 2004 @09:46PM (#10649311) Homepage Journal
    I think that deserved +1 Funny.

    Although the idea that C++ compiled object code is bloated is incorrect. It's normally either due to inexperience with the language or due to a poor compiler implementation. Part of the problem is that on old compilers, template instatiations were actually included once for every object file that refered to one. More recent compilers can identify and remove duplicates at link time, or can save templates in a separate file and link it in at the end of the build. (For some templates, though, you can actually be better off with one in each file if each file uses inline member functions, and each uses a different one).

    Sure C++ has it's faults, but bloatedness is not one of them - although a standard library may be bloated, but that's not an issue for the kernel.
  • Re:Progress (Score:1, Informative)

    by ucblockhead ( 63650 ) on Wednesday October 27, 2004 @09:54PM (#10649358) Homepage Journal
    The above C code can be deciphered simply by reading the code. Sure, it may be difficult because it isn't great code, but it can be done.

    On the other hand, if the above were C++ code, it could mean absolutely anything, depending on how operators were overloaded. Somebody could have defined "^" to play the star spangled banner on the system speaker for all you know. In C++, you can never really say for sure what anything means without looking in every single include file.

  • by defile ( 1059 ) on Wednesday October 27, 2004 @10:18PM (#10649501) Homepage Journal
    Some people say exceptions. I say goto. Easy to understand, easy to implement, and very clean IMO:

    int addclient(int s,struct sockpair *sp)
    {
    struct sockaddr_in sin;
    socklen_t sl;
    int local,remote;

    sl = sizeof (struct sockaddr_in);
    if (-1 == (local = accept(s,(struct sockaddr *)&sin,&sl))) {
    perror("accept()");
    goto just_return;
    }
    fcntl(local,F_SETFL,O_NONBLOCK);

    if (extent >= TCPFWD_NO) {
    fprintf(stderr,"error: out of buckets! %u >= %u\n",extent,TCPFWD_NO);
    goto close_local;
    }

    if (-1 == (remote = socket(PF_INET,SOCK_STREAM,0))) {
    perror("socket()");
    goto close_local;
    }

    /* reuse sin struct from accept() */
    memset(&sin,0,sizeof (struct sockaddr));

    sin.sin_family = AF_INET;
    sin.sin_port = htons(remote_port);
    sin.sin_addr.s_addr = inet_addr(remote_addr);

    if (INADDR_NONE == sin.sin_addr.s_addr) {
    fprintf(stderr,"inet_addr('%s'): failed\n",remote_addr);
    goto close_remote_local;
    }
    if (-1 == connect(remote,(struct sockaddr *)&sin,
    sizeof (struct sockaddr_in))) {
    perror("connect()");
    goto close_remote_local;
    }
    fcntl(remote,F_SETFL,O_NONBLOCK);

    sp[extent].allocated = 1;
    sp[extent].a = local;
    sp[extent].b = remote;

    extent++;
    return 0;

    close_remote_local:
    close(remote);
    close_local:
    close(local);
    just_return:
    return -1;
    }
  • Re:More Confusion (Score:2, Informative)

    by tomstdenis ( 446163 ) <tomstdenis@g[ ]l.com ['mai' in gap]> on Wednesday October 27, 2004 @10:42PM (#10649639) Homepage
    Well the major difference between C and C++ being that C++ supports "native" classes while in C you emulate them with arrays of stuctures.

    A class is a way of organizing "objects" in a hiarchical manner. You could almost say an OOP manner. The fact you can do more with C++ doesn't take away the fact that oop is the major difference. In fact I can't think of any other reason to use C++ over C aside from classes and the various forms of inheritance.

    The point is C didn't borrow what C++ had to offer not because the ISO C committee is lazy or incompetent but that C solves DIFFERENT problems.
  • by alder ( 31602 ) on Wednesday October 27, 2004 @11:12PM (#10649815)
    It doesn't add C++ support to the kernel...
    That's not what the articel says ;-) - "We have implemented a complete kernel level run-time support for C++ in the Linux kernel." And a bit farther: "The implementation of the C++ ABI is based on the implementation provided with the source of the GNU g++ compiler. We modified it to run in kernel space..."
  • Advantages of C++ (Score:3, Informative)

    by Spy der Mann ( 805235 ) <spydermann...slashdot@@@gmail...com> on Wednesday October 27, 2004 @11:17PM (#10649847) Homepage Journal
    If the Kernel is C++, this means the API calls can ALSO be C++ (with some restrictions, of course). This could mean no more kernel-recompiling for loading modules, no more .so recompiling and ending the .os dependancy hell...

    What we're talking about is using a whole new computing paradigm in the very core of an operating system. (it may be not new for apps, but for the kernel... just think about it).

    As an OOP'er, I'm frankly excited by the idea.

    And no, we're not talking about interpreted runtime languages like C# or java. We're talking about the REAL thing.

    C++ means that the code will be easier to maintain, changes will be easier to track, and who knows. Perhaps a boost in the development that might JUST be what Linux needs to defeat Winblows as the next Desktop OS.
  • Re:More Confusion (Score:4, Informative)

    by I_Love_Pocky! ( 751171 ) on Wednesday October 27, 2004 @11:28PM (#10649922)
    Your first three are part of OOP [hint: Java has them too]

    Sorry to break it to you pal, but you don't have to have classes to use these constructs, they work perfectly well with primitives and structs. Obviously they become much more useful in an OOP world, but they aren't part of OOP.

    pass-by-reference is not a programming methodlogy either... it's just a function of C++.

    No one said anything about programing methodologies. Your original post said:
    In fact I can't think of any other reasons to use C++ over C aside from classes and the various forms of inheritance.

    I just stated some language features available in C++ that aren't in C that are potential reason to use C++ over C (that aren't related to classes and inheritance).
  • Re:What about BeOS? (Score:2, Informative)

    by Anonymous Coward on Thursday October 28, 2004 @12:31AM (#10650312)
    Be had a strict "no c++ in the kernel" rule. You're correct in that they did use c++ extensively in user space.
  • by Anonymous Coward on Thursday October 28, 2004 @12:48AM (#10650445)
    Stop talking out of your ass. The Windows kernel developers use structured exception handling that was developed during the OS/2 days. The resulting code ends up nice looking and manageable because unlike C++ exceptions, this one also handles hardware exceptions (among other nifty features).
  • by Anonymous Coward on Thursday October 28, 2004 @01:13AM (#10650615)
    Yes, "undefined behavior" means, "this is not a feature of the language; DO NOT EVER DO THIS, EVER!". That is, it's a syntactically valid construct with no semantics attached to it. Since there is no semantic value in the statement, you should never use it. Just for the record, C has undefined behavior as well. Try the defined behavior of "int *px = 0; int x = *px;" for starters.
  • Re:nice (Score:1, Informative)

    by Anonymous Coward on Thursday October 28, 2004 @02:31AM (#10650977)
    IE's renderering engine is not used to display anything in windows explorer except when you open up html files using the file manager or use that stupid webview thing which wastes space by putting dumb shit on the sides and top of the listview by default.

    Can you give me a reference on DRM features being built into DirectX? If you mean the WMV codecs, that's not something anybody would consider DirectX.

    The kernel definitely will not be rewritten in C#. Maybe they'll add a subsystem written in C# way in the future but definitely the low level NT api will be in C with a few bits in assembly.

    Trolling, are we?
  • by halldorisak ( 825925 ) on Thursday October 28, 2004 @04:48AM (#10651470)
    These changes would definately be applicable to user space as well, and indeed we mention it in our paper. In kernel however they are more important as performance is normally of more concern.

    Ideally you should be able to turn on these optimizations by a switch. If any g++ developer is out there I'd be more than happy to explain what we did and they are free to use it.

    Some of the overhead in the g++ exception implementation arises from the fact that ease of debugging is considered important. However in kernel space that does not apply.
  • Nope (Score:1, Informative)

    by Anonymous Coward on Thursday October 28, 2004 @05:02AM (#10651507)
    C solves the same problems as C++. It makes different methods of solution easier.
    In many problems, the best solution is a procedural function. In some, it is an OO design. I've written polymorphic functions (badly, admittedly) in Fortran 77 with VAX extensions %REF and %LOC. C++ makes it *easier* to do this.

    One of the cardinal sins of the new C++ programmer is making *everything* an object. Makes the program impossible to debug.

    Two things bug me, though, in combination:

    Function Overloading is NOT recommended for the New/Delete functions. That is the ONE place I would see great benefit from overloading. You can write your own pooling mechanism, ad reference counts and so on by overloading the new and delete function. Why not?
  • Templates (Score:2, Informative)

    by wtd ( 791730 ) on Thursday October 28, 2004 @05:44AM (#10651614)
    You miss what is probably the biggest advantage of C++ (and possibly one of the most controversial).

    Templates allow for some incredibly slick code, and vastly improve both programmer productivity and type safety.
  • by downbad ( 793562 ) on Thursday October 28, 2004 @03:07PM (#10656478)
    according to these benchmarks [bulk.fefe.de], linux 2.6 is faster freebsd 5.1.
  • by Carewolf ( 581105 ) on Thursday October 28, 2004 @04:08PM (#10657059) Homepage
    What he is saying is that exceptions should only be used as runtime assertions.

The last person that quit or was fired will be held responsible for everything that goes wrong -- until the next person quits or is fired.

Working...