Discussing the article: "Master MQL5 from beginner to pro (Part II): Basic data types and use of variable" - page 2
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Ahem... I'm embarrassed to ask, but I have to....
In short, why does a neophyte need such a deep understanding of literals?
P.S. I personally, though not a neophyte, failed your test without answering a single question correctly. I met something similar in textbooks - either in Java or in PHP - but it was so long ago, and it doesn't correspond to the practical code I had to read or write until now... I'm not going to be a june in your office. And... what?
P.P.S. I think that if you write an article about literals, it might be useful not only for me. ;-) Especially if you share your experience, which is not in the help.... However, undocumented features usually embarrass me a lot, because they change too often in new versions, but, you never know.... Maybe it will be really important or at least useful?
You see. The question is not how often it happens, but that people don't know and don't want to know the subtleties. And about bringing in types, you need to know that because it's the foundation of the basics. You get so much pain through it. By the way, this code is not about type conversion, but for you to think about:
So, based on the help, everything is fine here. Only, for me personally, there is a nuance. According to the developers' claims, mql is written in C++, and in C++ you can't do that, it's UB, but in C everything is legal. I have seen such code on pluses often, and yes it worked and works, but personally I am somehow scared to write like that, but whether mql developers are scared, I don't know. That's why I will never do this in mql, because I don't know the implementation.
According to the developers' claims, mql is written in C++, and in C++ you can't do that, it's UB, but in C everything is legal.
Excuse me, but the developers claim that the MQL programming language is as close as possible to C++, not written in it. ))
Regards, Vladimir.
And about type conversion, it is necessary to know it, as it is the basis of the basics.
And I won't even try to argue about it. I totally agree. It's just... Well, not all C constructs are equally useful in MQL! :-)
Regarding the code "to think about"... Since I am not familiar with C (both of them), this code looks like a game to me. In the help, the enum type is referred to integer types, and I didn't even think that it is a structure at all. Its meaning is quite different... But thanks, now I'll know it - although it's of no use to me personally, I won't use it at all in this form.
So, based on the help, everything is normal here.
Can I have a link?
Regarding the code "to think about"... Since I am not familiar with C (both of them), this code looks like a game to me. In the help, the enum type is referred to integer types, and I didn't even think that it is a structure at all. Its meaning is quite different... But thanks, now I'll know - although it's of no use to me personally, I won't use it :-).
This is the game. A person must have written from the ceiling and mixed up enum and union. His example does not compile. Enum is not a structure but a 4-byte integer. If you take union, it works perfectly well in C++ and MQL.
PS. Regarding the first example from Jun's interview and the question about how often it happens - of course it doesn't happen in pure form, because the example is refined, but very often signed and unsigned integers are used in code mixed together, and problems are quite probable here.This is nonsense. The person must have written from the ceiling and mixed up enum and union. His example does not compile. Enum is not a structure but a 4-byte integer. If you take union, it works perfectly well in C++ and MQL.
PS. Regarding the first example from Jun's interview and the question about how often it happens - of course it doesn't happen in its pure form, because the example is refined, but very often signed and unsigned integers are used in code mixed together, and here problems are quite likely.Naturally union)))))
About the rest: https: //en.cppreference.com/w/cpp/language/union
And yes, I know what it says next
Except that msvs, from whose help it is taken, doesn't claim the second one, though nobody has come across it yet. g++ and clang haven't looked at what they say about it, but it's hardly different.
If you want to use it that way, use it - it's your right and your pain, if anything happens))).
Naturally))))
About the rest: https: //en.cppreference.com/w/cpp/language/union
cppreference is a useful resource, but due to its reference nature it cannot contain all the nuances that can be found only in language specifications. To generalise them, it is easier to look at stackoverflow, and as a summary - for primitive types, bitwise "transfer" of values is guaranteed when reading a field, even if it has not been written to.
This is nonsense. A person must have written from the ceiling and mixed up enum and union. His example does not compile. Enum is not a structure but a 4-byte integer. If you take union, it works perfectly well in C++ and MQL.
PS. Regarding the first example from Jun's interview and the question about how often it happens - of course it doesn't happen in its pure form, because the example is refined, but very often signed and unsigned integers are used in code mixed together, and problems are quite probable here.Phew, the world picture is restored! :-) I'm just finishing about unions and other complex types (hopefully, if there are no more blunders, it should be out next week).
P.S. MetaEditor does not highlight literals with suffixes `u` and `ull`, but compiles them. At the same time, it highlights `f` but reports an error.... I wonder if this is a bug or a hint? :-)
If you are a beginner and are confused by our debate, let me explain that in C (and also C++) you can add suffixes to numeric literals that change the data type. For example, the suffix `u` turns an ordinary integer(int) into an unsigned integer(uint).
Try to execute a slightly modified script suggested by Vladimir Simakov (pay attention to the absence of spaces between numbers and letters, it is important):
This script in the first lines outputs the type names of some literals that are compiled in MQL5.
I may not have compiled all working suffixes, I hope C specialists will correct me. Just try to understand the logic - based on the material of the article, the script output and our discussion, and if everything is not clear at all - ask questions.