| |
OVM also supports the concept of a constant. Constants are similar to variables except that the constant’s value is assigned once, and only once by the OVM compiler at compile time. Constants can be used in places where a literal of the same type would otherwise have been required. The type of the constant can be integer, boolean, or string and the initialising value is checked by the OVM compiler. Well named constants can make scripts easier to read because the constant name explains the purpose of the value of it holds.
The syntax for defining a constant and its value is
@constant type constantname = constant expressionFor example.
@constant integer fred = 10 ! define integer constant fred @constant boolean mary = true ! define boolean constant mary @constant string jane = "Hello" ! define string constant jane @comment(fred," ",mary," ",jane) ! display the values of the constantsMultiple constants of the same type may be defined on a single line.
@constant integer t1 = 100, t2 = 200 ! define two integer constantsConstants may be used to initialise other constants and the dimensions of arrays.
@constant integer t3 = t1 + t2 ! t3 will have the value 300 @integer myarray[t3] ! define an array of 300 elements
| |
| This publication has been prepared and written by Telstra Corporation Limited (ACN 051 775 556), and is copyright. Other than for the purposes of and subject to the conditions prescribed under the Copyright Act, no part of it may in any form or by any means (electronic, mechanical, microcopying, photocopying, recording or otherwise) be reproduced, stored in a retrieval system or transmitted without prior written permission from the document controller. Product or company names are trademarks or registered trademarks of their respective holders. Note for non-Telstra readers: The contents of this publication are subject to change without notice. All efforts have been made to ensure the accuracy of this publication. Notwithstanding, Telstra Corporation Limited does not assume responsibility for any errors nor for any consequences arising from any errors in this publication. |