digitalmars.D - Re: C++ frequently questioned answers
- Bruce Adams <tortoise_74 yeah.who.co.uk> Oct 29 2007
TomD Wrote:Walter Bright Wrote:An interesting and sometimes amusing read: http://yosefk.com/c++fqa/
But I wonder if the following is also true for D: ----snip--- [10.1] What's the deal with constructors? FAQ: A constructor initializes an object given a chunk of memory having arbitrary (undefined) state, the way "init functions" do. It may acquire resource like memory, files, etc. "Ctor" is a common abbreviation. FQA: That's right - constructors initialize objects. In particular, constructors don't allocate the chunk of memory used for storing the object. This is done by the code calling a constructor. The compiler thus has to know the size of a memory chunk needed to store an object of a class (this is the value substituted for sizeof(MyClass)) at each point where the class is used. That means knowing all members (public & private). This is a key reason why changing the private parts of a C++ class definition requires recompilation of all calling code, effectively making the private members a part of the public interface. ---snap--- Given the compilation speed of DMD, it does not bother me, but still, he has a point here. Ciao Tom
I have been bothered by that for many years. I had an idea to implement truly opaque types by having the size of the object used as a link time variable. If I recall it wasn't possible using the ELF binary format. I think I ended up using code generation and the PIMPL idiom instead. However, D is not constrained to use an existing object format itself only for its C/C++ interface. Regards, Bruce.
Oct 29 2007