[lkml]   [1999]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: linux headers and C++
Nix wrote:
> C++ templates, correctly used, are, eg, a type-enforcement system for
> untyped containers; that is, you have a class that implements, say, a
> list, in terms of void pointers; then you implement an almost empty
> template on top of that that *privately* inherits from the untyped list,
> and reimplements its accessors in terms of typesafe casts to the untyped
> list accessors.

That's done in Linux in C already: see <linux/list.h>.

> This works, and has zero bloat; in fact it is *more* compact than the
> analogous magic-number-based implementation in C, relying instead upon
> the RTTI structures already generated by the compiler.

Nonsense. (a) RTTI has nothing to do with generic containers and
typesafe accessors; (b) the wrapper macros aren't typesafe in C but they
certainly don't use magic numbers; (c) when RTTI _is_ used for variant
types, a C switch is usually faster and smaller; (d) RTTI has other

> So please stop saying templates are bloated. They *are* easy to produce
> bloated stuff in, and could probably be faulted for that; but they are
> *not* intrinsically bloat creators. It is perfectly possible (and easy)
> to produce non-bloating, typesafe stuff with templates.

We know. It doesn't happen in practice: even the STL does not work the
way you describe. (It can be, but you have to do it quite deliberately
and write the type conversions yourself).

-- Jamie

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:52    [W:0.024 / U:15.740 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site