Attribute 'to_string'
The pragma has an effect on how the result of the conversion of an enumeration component with the operator TO_STRING/TO_WSTRING is output: If the enumeration declaration is provided with the pragma, the name of the enumeration component appears as a string instead of the numerical value.
Syntax: {attribute 'to_string'}
Insertion location: Line above the declaration of the enumeration.
![]()  | Available from TC3.1 Build 4024  | 
Sample:
Enumeration E_Sample
{attribute 'qualified_only'}
{attribute 'strict'}
{attribute 'to_string'}
TYPE E_Sample :
(
    eInit := 0,
    eStart,
    eStop
);
END_TYPEProgram MAIN
PROGRAM MAIN
VAR
    eSample         : E_Sample;
    nCurrentValue   : INT;
    sCurrentValue   : STRING;
    wsCurrentValue  : WSTRING;
 
    sComponent      : STRING;
    wsComponent     : WSTRING;
END_VARnCurrentValue  := eSample; 
sCurrentValue  := TO_STRING(eSample); 
wsCurrentValue := TO_WSTRING(eSample); 
sComponent     := TO_STRING(E_Sample.eStart); 
wsComponent    := TO_WSTRING(E_Sample.eStop);
Result of the assignments/conversion functions:
- Value of nCurrentValue: 0
 - Value of sCurrentValue: 'eInit'
 - Value of wsCurrentValue: "eInit"
 - Value of sComponent: 'eStart'
 - Value of wsComponent: "eStop"
 
Result if the enumeration were not to be declared with the attribute 'to_string':
- Value of nCurrentValue: 0
 - Value of sCurrentValue: '0'
 - Value of wsCurrentValue: "0"
 - Value of sComponent: '1'
 - Value of wsComponent: "2"
 
See also:
