Assembly Language Help (alang.hlp) (Table of Contents; Topic list)
Variable Length
                                             Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
  Syntax:   LENGTHOF variable
 
            SIZEOF variable
 
            SIZEOF type
 
            LENGTH expression
 
            SIZE expression
 
  See also: WIDTH, TYPE, SIZESTR, DUP, BYTE, MACRO,
            MASM 5.1 Compatibility
 
  Description:
 
     The LENGTHOF operator returns the number of data items allocated
     for <variable>. The SIZEOF operator returns the total number of
     bytes allocated for <variable> or the size of <type> in bytes. For
     variables, SIZEOF is equal to the value of LENGTHOF times the
     number of bytes in each element.
 
     The LENGTH and SIZE operators are allowed for compatibility with
     previous versions of the assembler. When applied to a data label,
     the LENGTH operator returns the number of elements created by the
     DUP operator; otherwise it returns 1. When applied to a data
     label, the SIZE operator returns the number of bytes allocated by
     the first initializer at the <variable> label.
 
     In MASM 5.1, the LENGTH operator, when applied to a record type, returns
     the total number of bits in a record definition. In MASM 6.1, the state-
     ment LENGTH <recordName> returns error A2143. MASM 6.1 uses the
     SIZEOF operator to return information about records.
 
     With OPTION M510, you can apply the LENGTH and SIZE operators to any
     label. For a code label, SIZE returns a value of 0FFFFh for NEAR and
     0FFFEh for FAR. LENGTH always returns a value of 1. For strings, SIZE
     and LENGTH both return 1.
 
     Without OPTION M510, SIZE returns values of 0FF01h, 0FF02h, 0FF04h,
     0FF05h, and 0FF06h for SHORT, NEAR16, NEAR32, FAR16, and FAR32 labels,
     respectively. LENGTH returns 1 except when used with DUP, in which case
     it returns the outermost count. For arrays initialized with DUP, SIZE
     returns the length multiplied by the size of the type.
 
     The LENGTHOF and SIZEOF operators in MASM 6.1 handle arrays much more
     consistently. These operators return the number of data items and the
     number of bytes in an initializer.
                                    -♦-