Safer casts

Janice Caron caron800 at googlemail.com
Sun May 11 15:39:34 PDT 2008


On 11/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
> From what I know, an efficient STL implementation would use C style
>  containers with void* under the hood to minimize executable bloat.

I /think/ I get what you're saying here, which is (correct me if I'm
wrong, but) given

    class C {}
    class D {}

then

    Vector!(C) c;
    Vector!(D) d;

produces two instantiations of Vector! - one for C and one for D - and
yet those instantiations will produce byte-for-byte identical machine
code.

However - this is a linker problem, not a template problem, and Walter
has said that this will be fixed in the future. So in the future,
whenever any two or more segments consist of identical bytes, the
linker may keep one and throw the rest away.

The moral of the story is: specify your intent, but leave the
implementation to the compiler/linker.

If you try to "outguess" the compiler, by instantiating only one
single Vector!(void*), then in the long run, all you are doing is
creating obfuscated code for short term gain.



More information about the Digitalmars-d mailing list