[Bug 88] New: Add .isizeof property for compile-time instance size determination

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 6 12:52:28 PDT 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=88

           Summary: Add .isizeof property for compile-time instance size
                    determination
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: sean at f4.ca


As D lacks a lexical specifier for class reference types there is currently no
way to determine the size of a class instance at compile-time.  A simple
solution would be to add a new property, valid for pointer and reference types,
that evaluates to the size of the referenced type.  Thus:

(byte*).isizeof == byte.sizeof == 1
(byte**).isizeof == (byte*).sizeof == 4 (on 32-bit systems)
byte.isizeof == Error: property isizeof is only valid for reference types.

MyClass { int x, y; }
MyClass.isizeof == 8
(MyClass*).isizeof == MyClass.sizeof == 4 (on 32-bit systems)

Multiple levels of indirection can be eliminated using recursive templates, so
there is no reason to collapse multiple levels of indirection and return the
size of the final referenced type.


-- 




More information about the Digitalmars-d-bugs mailing list