Size of a class instance at compile time

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Jan 13 12:55:14 PST 2007


Sean Kelly wrote:
> Frits van Bommel wrote:
>>
>> You also forgot to take alignment gaps into account.
> 
> I think this may be a problem.  The ABI allows class data to be 
> rearranged, so alignment gaps can't be predicted (I think) from the 
> output of tupleof.  I still wish we could get .isizeof for this :-p

As I noted earlier in that post, the ABI indeed doesn't specify the 
format of the non-static member part of an object. It seems to be one of 
the incomplete parts.

But from my experiments it seems the current compiler (v1.0) doesn't 
reorder fields.
I've tested my code with several layouts and AFAICT it consistently 
provides the same answer as a runtime classinfo.init.length. So assuming 
no edge cases[1] are triggered it should work until the next ABI break 
at the very least...
Since ABI breaks seem to be indicated by red 'Need to recompile 
because:' clauses in the changelog, it should be pretty clear when this 
needs to be changed.


[1]: e.g. I haven't tested using anything with explicit align(N) 
declarations, not sure what happens there (would .alignof be adjusted?).


More information about the Digitalmars-d-learn mailing list