1
+ // RUN: (%COMPILE %s && %RUN ) | %CHECK %s
2
+
3
+ TYPE PositionWithExtraMetadata:
4
+ STRUCT
5
+ x: REAL ;
6
+ y: REAL ;
7
+ data: ARRAY [1 ..100 ] OF STRING ;
8
+ END_STRUCT
9
+ END_TYPE
10
+
11
+ FUNCTION_BLOCK FbA
12
+ VAR
13
+ localStruct: PositionWithExtraMetadata := (x := 1.0 , y := 2.0 , data := [' Data 1' , ' Data 2' , ' Data 3' ]);
14
+ localStringArray: ARRAY [1 ..3 ] OF STRING := [' Value 1' , ' Value 2' , ' Value 3' ];
15
+ localStructArray: ARRAY [1 ..3 ] OF PositionWithExtraMetadata := [
16
+ (x := 3.0 , y := 4.0 , data := [' Data 4' , ' Data 5' , ' Data 6' ]),
17
+ (x := 5.0 , y := 6.0 , data := [' Data 7' , ' Data 8' , ' Data 9' ]),
18
+ (x := 7.0 , y := 8.0 , data := [' Data 10' , ' Data 11' , ' Data 12' ])
19
+ ];
20
+ END_VAR
21
+
22
+ METHOD returnString: STRING
23
+ returnString := ' FbA::returnString' ;
24
+ END_METHOD
25
+
26
+ METHOD returnStruct: PositionWithExtraMetadata
27
+ returnStruct := localStruct;
28
+ END_METHOD
29
+
30
+ METHOD returnStringArray: ARRAY [1 ..3 ] OF STRING
31
+ returnStringArray := localStringArray;
32
+ END_METHOD
33
+
34
+ METHOD returnStructArray: ARRAY [1 ..3 ] OF PositionWithExtraMetadata
35
+ returnStructArray := localStructArray;
36
+ END_METHOD
37
+ END_FUNCTION_BLOCK
38
+
39
+ FUNCTION main
40
+ VAR
41
+ instanceA: FbA ;
42
+ returnStringPtr: POINTER TO FbA .returnString := ADR (instanceA.returnString);
43
+ returnStructPtr: POINTER TO FbA .returnStruct := ADR (instanceA.returnStruct);
44
+ returnStringArrayPtr: POINTER TO FbA .returnStringArray := ADR (instanceA.returnStringArray);
45
+ returnStructArrayPtr: POINTER TO FbA .returnStructArray := ADR (instanceA.returnStructArray);
46
+
47
+ localReturnString: STRING ;
48
+ localReturnStruct: PositionWithExtraMetadata ;
49
+ localReturnStringArray: ARRAY [1 ..3 ] OF STRING ;
50
+ localReturnStructArray: ARRAY [1 ..3 ] OF PositionWithExtraMetadata ;
51
+ END_VAR
52
+
53
+ // localReturnString := instanceA.returnString();
54
+ localReturnString := returnStringPtr^ (instanceA);
55
+ printf(' localReturnString = %s$N' , ADR (localReturnString));
56
+
57
+ // localReturnStruct := instanceA.returnStruct();
58
+ localReturnStruct := returnStructPtr^ (instanceA);
59
+ printf(' localReturnStruct.x = %f$N' , localReturnStruct.x);
60
+ printf(' localReturnStruct.y = %f$N' , localReturnStruct.y);
61
+ printf(' localReturnStruct.data[1] = %s$N' , ADR (localReturnStruct.data[1 ]));
62
+ printf(' localReturnStruct.data[2] = %s$N' , ADR (localReturnStruct.data[2 ]));
63
+ printf(' localReturnStruct.data[3] = %s$N' , ADR (localReturnStruct.data[3 ]));
64
+
65
+ // localReturnStringArray := instanceA.returnStringArray();
66
+ localReturnStringArray := returnStringArrayPtr^ (instanceA);
67
+ printf(' localReturnStringArray[1] = %s$N' , ADR (localReturnStringArray[1 ]));
68
+ printf(' localReturnStringArray[2] = %s$N' , ADR (localReturnStringArray[2 ]));
69
+ printf(' localReturnStringArray[3] = %s$N' , ADR (localReturnStringArray[3 ]));
70
+
71
+ // localReturnStructArray := instanceA.returnStructArray();
72
+ localReturnStructArray := returnStructArrayPtr^ (instanceA);
73
+ printf(' localReturnStructArray[1].x = %f$N' , localReturnStructArray[1 ].x);
74
+ printf(' localReturnStructArray[1].y = %f$N' , localReturnStructArray[1 ].y);
75
+ printf(' localReturnStructArray[1].data[1] = %s$N' , ADR (localReturnStructArray[1 ].data[1 ]));
76
+ printf(' localReturnStructArray[1].data[2] = %s$N' , ADR (localReturnStructArray[1 ].data[2 ]));
77
+ printf(' localReturnStructArray[1].data[3] = %s$N' , ADR (localReturnStructArray[1 ].data[3 ]));
78
+ printf(' localReturnStructArray[2].x = %f$N' , localReturnStructArray[2 ].x);
79
+ printf(' localReturnStructArray[2].y = %f$N' , localReturnStructArray[2 ].y);
80
+ printf(' localReturnStructArray[2].data[1] = %s$N' , ADR (localReturnStructArray[2 ].data[1 ]));
81
+ printf(' localReturnStructArray[2].data[2] = %s$N' , ADR (localReturnStructArray[2 ].data[2 ]));
82
+ printf(' localReturnStructArray[2].data[3] = %s$N' , ADR (localReturnStructArray[2 ].data[3 ]));
83
+ printf(' localReturnStructArray[3].x = %f$N' , localReturnStructArray[3 ].x);
84
+ printf(' localReturnStructArray[3].y = %f$N' , localReturnStructArray[3 ].y);
85
+ printf(' localReturnStructArray[3].data[1] = %s$N' , ADR (localReturnStructArray[3 ].data[1 ]));
86
+ printf(' localReturnStructArray[3].data[2] = %s$N' , ADR (localReturnStructArray[3 ].data[2 ]));
87
+ printf(' localReturnStructArray[3].data[3] = %s$N' , ADR (localReturnStructArray[3 ].data[3 ]));
88
+ END_FUNCTION
0 commit comments