Suggestion: Implicit Derived[]-to-Base[] conversions should be disallowed

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jan 30 11:51:29 PST 2007


James Dennett wrote:
> maXmo wrote:
>>> we can write generic array operations by them, not relying on Derived[]-to-Base[] conversions.
>> but wouldn't templates bloat your code? I don't know
>> how D deals with them but in C++ when you instantiate
>> template with different parameters you get several 
>> instances of the template, all the templated code gets copied.
> 
> Except when it doesn't, such as when an implementation
> notices that the generated code is the same (such as
> when the templated is instantiated over a number of
> types whose representations and behavior at the level
> of machine code is identical) and collapses them to a
> single instance.

And as long as function pointers aren't compared[1]. Thought that 
behavior could be preserved by having multiple entry points into the 
same function[2].
Also, such folding will probably not work across object files[3], unless 
you implement it into the linker. AFAIK current linkers don't support 
this[4].


[1]: They must presumably be different for different functions, right?
[2]: A few nops at the beginning, entry points with just a jump, whatever.
[3]: When compiling separately, at least.
[4]: Except if you incorporate the entire machine code into the section 
name...

> It's good to distinguish features that are *forced* by
> a language design choice and those which depend on how
> an implementation chooses to work.  (It's also good to
> take into account how much work is involved in the
> implementation of a feature; if it's too much, it likely
> won't be done well.)

Indeed.



More information about the Digitalmars-d mailing list