I've got the following script:
void main()
{
array<string> arr;
arr.insertLast("hello");
const string s = arr[0];
Print(s);
}
The array is the add_ons one and Print() is being registered as follows:
r = engine->RegisterGlobalFunction("void Print(string &in)", asFUNCTION(PrintString), asCALL_CDECL);
That produces the following byte code:
void main()
Temps: 2, 4
Variables:
001: array<string> arr
003: const string s
002: string {noname}
- 3,2 - array<string> arr;
0 4 * SUSPEND
1 4 * VarDecl 0
1 4 * CALL 114 (array<string>@ factstub())
3 4 * STOREOBJ v1
- 4,2 - arr.insertLast("hello");
4 4 * SUSPEND
5 4 * STR 0 (l:5 s:"hello")
6 6 * CALLSYS 33 (const string& _string_factory_(const int, const uint8&in))
8 4 * PshRPtr
9 5 * PSF v2
10 6 * CALLSYS 35 (string::string(const string&in))
12 4 * ObjInfo v2, 1
12 4 * VAR v2
13 5 * PshVPtr v1
14 6 * GETREF 1
15 6 * CALLSYS 122 (void array::insertLast(const string&in))
17 4 * PSF v2
18 5 * CALLSYS 36 (string::~string())
- 6,2 - const string s = arr[0];
20 4 * ObjInfo v2, 0
20 4 * SUSPEND
21 4 * VarDecl 1
21 4 * PshC4 0x0 (i:0, f:0)
23 5 * PshVPtr v1
24 6 * CALLSYS 118 (string& array::opIndex(uint))
26 4 * PshRPtr
27 5 * PSF v3
28 6 * CALLSYS 34 (string::string())
30 5 * ObjInfo v3, 1
30 5 * PSF v3
31 6 * CALLSYS 37 (string& string::opAssign(const string&in))
- 7,2 - Print(s);
33 4 * SUSPEND
34 4 * PSF v2
35 5 * CALLSYS 34 (string::string())
37 4 * ObjInfo v2, 1
37 4 * PSF v3
38 5 * PSF v2
39 6 * CALLSYS 37 (string& string::opAssign(const string&in))
41 4 * PSF v2
42 5 * CALLSYS 107 (void Print(string&in))
44 4 * PSF v2
45 5 * CALLSYS 36 (string::~string())
- 8,2 - }
47 4 * ObjInfo v2, 0
47 4 * SUSPEND
48 4 * PSF v3
49 5 * CALLSYS 36 (string::~string())
51 4 * ObjInfo v3, 0
51 4 * FREE v1, 145445320
53 4 * 0:
53 4 * RET 0
In the byte code corresponding to the Print() call, why is a string temporary being created? I thought the "in" designation on Print()'s param was supposed to instruct the compiler that Print() will not modify that param..
Thank you very much!