Re: C++ in kernel (was Re: exception in a device driver)

Marc Espie (Marc.Espie@liafa.jussieu.fr)
Tue, 12 Jan 1999 10:49:39 +0100


On Tue, Jan 12, 1999 at 10:13:39AM +0100, Thomas Pornin wrote:
> In article <199901101152.MAA07245@quatramaran.ens.fr> you write:
> > template expansions can be incredibly powerful

> Actually kernel programming is a bit different. Code efficiency is most
> often I/O bound, and the important points are cache and TLB misses,
> not complete loop unrolling or other things like that. Note that the
> default optimization flag is -O2, not -O6. The C++ black magic may
> induce (silently and depending heavily on the compiler) extra memory
> accesses that are difficult to track down. This may be good for the
> average cpu-eating application, but I think that the kernel requires at
> least a specially tuned compiler (using C is then just tuning by hand).

You are definitely confusing issues here, I suspect deliberately,
knowing you :)

C++ template expansions can do the exact same things C macros do, with
strict type-checking, and with smarter behavior, since you can change
the code emitted depending on the type of the object.
This can also replace loop unrolling in some cases, with much MORE
control over what's goin on than with compiler flags.

On the other hand, we all know that the C and C++ front-ends of gcc
are somewhat different. The C++ front-end is newer and larger, and
right now, it does not emit the same RTL, even when faced with the
same code. It is slightly worse than the C front-end for efficiency
reasons.

But, mind you, there are no theoretical reasons things should be so.
It can be improved, which depends on people sending bug-reports.

Up till now, efficiency freaks have been using C and reporting
code generation problems to improve the C compiler. Not only does
the C compiler generate better code, it's getting MORE feedback
in that area ! Is this a vicious circle or what ?

This could be termed off-topic for linux-kernel, but I believe
it is vitally important that people with machine language
knowledge use and evaluate C/C++ compilers. Otherwise, we all lose.
Hence, having even a tiny little bit of linux drivers written in
C++ would be a huge gain for the C++ community.

-- 
	Marc Espie		
|anime, sf, juggling, unicycle, acrobatics, comics...
|AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
| `real programmers don't die, they just get out of beta'

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/