void main()
{
import std.stdio;
auto x = typeid(int);
writefln("%s, %s", x.init.length, x.init.ptr);
}
output:
Doing some research, I found this tidbit in history:
The only basic types that have init() defined are the ones that have non-zero initializers. I suppose we have 3 options:
1. Revise the documentation so it says “if this returns null with zero length, it means the type is initialized with all zeros, and use tsize to get the size of the type”
2. Add the appropriate overrides to all the druntime types.
3. We could make TypeInfo.init return (cast(void *)null)[0..tsize] by default, defaulting all inits to a sane value.
My personal preference is for 3, since it adds no new functions, and will fix any omissions that we haven’t discovered or that would be added in the future.
Clearly, though, this identifies how unused that function really is :)
I recall now, the compiler only sets up static data inside the typeinfo for things like classes and structs, and the TypeInfo_Struct init() function reads that when determining what to return.
Everything else is defined in druntime.
-Steve