Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> sizeof find size of variable or structure pp 144</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 SIZEOF              Find Size of Variable or Structure               pp 144

 Syntax:  SizeOf (Name) ;

 Type:    Integer

 Form:    Function

 Purpose: Returns number of bytes in memory that are occupied by a variable
          or defined Type.

 Notes:   SizeOf allows the program code to know how large a variable is
          at runtime.  The Move and FillChar procedures don't respect the
          bounds of the variables they interact with.  Both can easily overlay
          their destinations if the counts are incorrect.  SizeOf gives
          an accurate means of determining the size of the destination.


 ----------------------------------------------------------------------------


 Usage:
        CONST
          Count : Integer = 50            ;  { Variable count          }
       VAR
          Var1  : String [50]             ;  { Source string           }
          Var2  : String [80]             ;  { Destination string      }

       BEGIN
          Move (Var1,Var2,Count)          ;  { This will move ok       }
          Move (Var2,Var1,80)             ;  { This will overflow Var1 }
          Move (Var1,Var2,SizeOf(Var1))   ;  { This will move safely   }
       END.

See Also: FillChar Move

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson