Since a while it is possible to return objects from functions, so if you would want to measure a function returning an object, you would need to use this macro instead.
This is due to a limitation of the compiler, not being able to distinguish between r-values, l-values and objects.
So if you would write a function accepting an object, it needs to be passed as reference, but you cannot pass (from your example) the addition of two results from functions (f1() + f2()), as they are not implicitly converted by the MQL compiler into a temporary/hidden variable, therefore the function receiving this may not use a reference (int &var) as input.
C/C++ allows this in contrast, and creates a temporary l-value to be used as input to the function.
In fact, this is the last hurdle the MQL compiler has to it's way on supporting fully unified code generation.
Of course with one exception, enums.... These cannot be distinguished from objects in any meaningful way. At least I failed to do so up to now.
That's why three macros are required. Void is obvious. A function with no return value cannot be assigned to any variable. Return is used for explicit variable declaration. And Object is used to deal with references.
I'd be glad if anyone knew a way around this without altering the compiler.
But maybe, one day, Metaquotes will implement implicit r-value to l-value conversion for function call parameters.
By altering that part, you will create unnessary copies of the object. - Please use the O-Version of the macro for objects of type struct, class or interface....
BTW, this also compiles fine without editing the library...
By altering that part, you will create unnessary copies of the object. - Please use the O-Version of the macro for objects of type struct, class or interface....
Thank you all for the steady contributions, its not as easy to have an overview of all use cases, and by such complex integration, its easy to miss some edges....
Hope everything is beginning to work as expected slowly.... :-)
I have taken a look at this phenomenon, and I am sorry to disappoint you, but there is no way this can be influenced by us.
The MQL compiler has a few very strange behaviours concerning performance, and I have had the most ridicolous findings within source code. - I reported all of these things to Alexey from Metaquotes, and I never received a satisactory answer.
It might be, by adding some comment to the lib_debug.mqh, this effect could change and move to another function. - Yes, I know, htat sounds completley like abracadabra, but thats what it is. - If you would like to investigate on that issue more, I am very willing to share the proof with you, which I have also given to metaquotes to investigate....
You will find lots of inconsistencies when regarding performance measurements. - As said, and I am sure you can see as well ,the cod eis exactly the same for both functions, still one takes significant longer than the other. - Thats due to whatever the compiler does.
If you want, Ill share the project with you, you will get an even more detailed version of that problem. - Unsolved.
It compiles.
Result.
When do you need a macro for objects?
After these changes.
It compiles.
Result.
oh well...
Exactly for this you would need to use the object macro...
This compiles without altering the library:
By altering that part, you will create unnessary copies of the object. - Please use the O-Version of the macro for objects of type struct, class or interface....
BTW, this also compiles fine without editing the library...
void OnInit() { TimeIt(GetT<int>()); TimeItO(GetT<MqlTick>()); TimeItO(GetT<A>()); TimeItO(new A); TimeIt(GetT<A*>()); }Got it...
I never use if() without brackets....
Change this line (Line Number 3351 in lib_debug.mqh
to this line:
that will fix the error...
I will post the update on shared storage now... and update the CodeBase
Yes, MQLplus is a shared public project!
By altering that part, you will create unnessary copies of the object. - Please use the O-Version of the macro for objects of type struct, class or interface....
Thank you all for the steady contributions, its not as easy to have an overview of all use cases, and by such complex integration, its easy to miss some edges....
Hope everything is beginning to work as expected slowly.... :-)
I have taken a look at this phenomenon, and I am sorry to disappoint you, but there is no way this can be influenced by us.
The MQL compiler has a few very strange behaviours concerning performance, and I have had the most ridicolous findings within source code. - I reported all of these things to Alexey from Metaquotes, and I never received a satisactory answer.
It might be, by adding some comment to the lib_debug.mqh, this effect could change and move to another function. - Yes, I know, htat sounds completley like abracadabra, but thats what it is. - If you would like to investigate on that issue more, I am very willing to share the proof with you, which I have also given to metaquotes to investigate....
You will find lots of inconsistencies when regarding performance measurements. - As said, and I am sure you can see as well ,the cod eis exactly the same for both functions, still one takes significant longer than the other. - Thats due to whatever the compiler does.
If you want, Ill share the project with you, you will get an even more detailed version of that problem. - Unsolved.