Type Conversions
 
Description


    The ARMbasic compiler handles many conversions between INTEGER, SINGLE and STRING variables.

input INTEGER SINGLE STRING
INTEGER = yes no
SINGLE = yes no
STRING =   yes no*
FUNCTION (INTEGER param) yes no
FUNCTION (SINGLE param) yes no
FUNCTION (STRING param) no no
RETURN INTEGER-FUNCTION  yes no
RETURN SINGLE-FUNCTION yes no
RETURN STRING-FUNCTION no no
printf no no  no
Simple statements
lvalue = expression
Expression will be evaluated with the type of lvalue and conversions will be made to lvalue's type as allowed above
Complex Statements
IF (expressionA)  then  RETURN  expressionB else RETURN expressionC
ExpressionA is evaluated depending on the first operand found (scanning from left to right)
ExpressionB and ExpressionC will be converted to the type of the FUNCTION as allowed in the table.
 
IF (expressionA) then lvalue = expressionB
ExpressionA is evaluated depending on the first operand found (scanning from left to right)
ExpressionB will be evaluated with the type of lvalue
Parameter Passing
FUNCTION someFunction (paramA AS typeA,  paramB AS typeB,  paramC AS typeC) AS funtionType
    ...
lvalue = someFunction (ExpressionA,  ExpressionB, ExpressionC)
ExpressionA, ExpressionB and ExpressionC will be evaluated depending on the type of the parameter as declared.
If the type of someFunction is different than the type of lvalue it will be converted as allowed.
printf
printf is a special built in SUB, there is no type checking or conversion between parameters and the format-string, so if you try to use a %d to print a SINGLE type variable, you will not get the expected results.
INTEGER/STRING
INTEGERs are converted to string type and concatenated with the rest of the string expression.
To convert a STRING to an INTEGER use the built-in VAL function.
Currently you must use SPRINTF to convert a SINGLE to a STRING
There is no built-in conversion from STRING to SINGLE.
See also