[LC++]OS Programming

hursh hursh at infonet.isl.net
Mon Oct 7 07:38:01 UTC 2002


Jan Reimers wrote:
> On Wednesday 25 September 2002 09:36 pm, Paul Gearon wrote:
> 
>>In the case of Linux it's due to performance and size.  Polymorphism
>>requires vtables, and vtables slow everything down considerably.

[snip]
> Also, polymoprhic function calls replace one of two things in non OO 
> programming 1) an if/switch statment, 2) calling a function from an array of 
> function pointers.  So there is no free lunch when the system design requires 
> runtime decisions.

So it's just a choice of letting C++ generate the vtables for you, or 
make them by hand.  Is there reason to believe today's C++ compilers are 
less efficient at this?

>>C++ also naturally creates larger binaries. 
> 
> 
> Yes absolutely, so for coding an OS you would have to make some rules like
> 1) No including <iostream>
> 2) Use a limited subset of the std. template conatiners
> 3) Be careful which functions are inline.
> etc.
> 
> i.e. you use a subset of C++ that is suitable to your task.

Actually, doesn't the Linux kernel have it's own internal C library 
instead of using a packaged one, like glibc?

1) I imagine they don't include the complete IO subsystem from the C 
standard.
2) I also imagine there is some overlap in utilities container 
implementations, like queues of various types.  There is probably other 
redundant code.
3) I'm sure they are already careful about what is written as a 
preprocessor macro.

Seems to me that one could do the same in C++ with more structure and 
without any sizable penalties.  It may take some careful C++ coding in a 
few places, but it not like the kernel doesn't have plenties of careful 
C coding.  I bet there is careful coding in implementing things that the 
C++ compiler would do for you.

> I think the main reason OS's are still mostly written in C is the maturity of 
> the standards and compiler technology.  Most notably there has only recently 
> been a standardization of the C++ ABI, but nobody has implemented it yet.  
> g++ is working towards that goal.

Sounds true enough, but I would bet that there is a health dose of 
language bigotry in there too.

Dan




More information about the tuxCPProgramming mailing list