Re: linux headers and C++

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Sun, 11 Jul 1999 20:31:49 +0200


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
overheads.

> 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 majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/