Errors, bugs, questions - page 2725

 
Vict:

Do you think your Sharp appeared in a clean field? Rooted in C, the structure is a dumb container with no extra sugar.

Well, man evolved from a monkey. But that doesn't mean man is a dumb monkey "without any extra sugar", does it? ) I've already explained that in fact MQL structures = C# structures, with a small difference: in C# they can still implement interfaces. interfaces, Carl! )

How can you be so sure? Calling a function from another translation unit/another module/cycles/compiler out of tune/... . Don't overestimate the capabilities of the optimizer. This is not Copy elision optimization that compilers are obliged to do. If optimizers get so smart and it stops costing anything, they will write in the next C standard: "default initialization does not leave an object in undefined state".

Because it's the most trivial and primitive thing that you cannot even call optimization. I think all the compilers do it by default even in Debug-mode. What can be easier? During code parsing, you have to track access to variables. If there is a repeated write operation and there was no read operation, then cut out the previous entry.

You can ignore it, but then don't be surprised that decent coders will look at you as a shit-coder when they see your structures stuffed with functions

I would rather call your approach to uninitialized operation shit-coding. What is the main quality a computer program must possess? Stability. With the same input data it must give unchangeable results. And you propose to forget about it. Somewhere you forgot to initialize a variable, somewhere you added a new field to the structure and it became uninitialized throughout the program and the program imploded. The program works this way and that way...

The C language was created in a distant past when hardware capabilities were very poor, so much of the optimization work was left to the programmer. If you are so itchy, why do you refer to C and not Assembler for example? Encode the trading systems in Assembler. I'm sure they will be the fastest, maybe even ahead of the market )

 
Alexey Navoykov:

Because it is the most trivial and primitive thing, which can hardly even be called optimization. I think all compilers do it by default even in Debug-mode. What could be easier? While parsing the code, monitor access to variables. If there is a repeated write operation and there was no read operation, then cut out the previous entry.

If the program was completely predictable at compile time, it wouldn't have to be executed at run time at all. It should by definition take something from the outside world and output a result based on it, and that's the uncertainty that gets in the way of the optimizer. Another secret - shared libraries are linked with the application in runtime, the optimizer can't trace anything there. There are a million more cases to be thrown out. (A million, Karl!)

Somewhere I forgot to initialize a variable or added a new field to a structure that became uninitialized in the whole program, and the program goes on. The program works this way and that way...

Somewhere I multiplied by 2 instead of 3, called fn() instead of fn_(), ... . If your hands are wrong, you are in trouble.

The C language was created long ago when hardware capabilities were very poor, that's why much of the optimization work was left to the programmer. If you're itching to do it, why do you refer to C and not Assembler? Encode the trading systems in Assembler. I'm sure they will be the fastest, maybe even ahead of the market.

for your reference: C standards (the latest, these are not C++ standards): C11, C18, C2x is being prepared. Rather, you wrote this as a result of incompetence.
 
Vict:

If the program were completely predictable at compile time, it wouldn't need to be executed at run time at all. By definition, it must take something from the outside world and output a result based on it, and this is an uncertainty that hinders the optimizer. Another secret - shared libraries are linked with the application in runtime, the optimizer can't trace anything there. There are a million more cases to be thrown out. A million, Karl!)

Data exchange with the outside world are special cases and require special solutions. We are talking about programming as such and those cases where the compiler is guaranteed to know that the variable is not controlled from the outside. And this must be the vast majority of cases. Otherwise you have a purely system programming, which is really better to do in C, or even better - in assembler.

Somewhere multiplied by 2 instead of 3, called fn() instead of fn_(), . . If your hands are crooked, trouble.

If you multiply by 2 instead of 3, you get a stable error in the program which is easy to diagnose and find. And if the variable is not initialized you get something that works now and then not, from time to time, with unpredictable consequences. In general, it is rather strange that I explain such basics to you, posing as an experienced programmer.

 
Alexey Navoykov:

Data exchange with the outside world - these are special cases, and they require special solutions. But we are talking about programming as such, and those cases where the compiler is guaranteed to know that the variable is not controlled from the outside. And this should be the vast majority of cases. Otherwise, you get a purely system programming, which is really better to do in C, or even better - in assembler.

Communication with the outside world is an essential part of any program. Let me repeat - otherwise it can be figured out in compile-time. For example, will the compiler cut the initialization here?

int i = 54;
if (read_socket() == SIGNAL) {
   fn(i);
}
i = 100;
...

// естественно, что никто не пишет такой бред:
int q = 3;
q = 7;
q = 9;
fq(q);

Obviously, it has no idea what read_socket() will return. The whole program is "permeated" by interaction with the outside world. + add a call to external modules here... .

If you multiply it by 2 instead of 3, you get a stable error in the program that is easy to diagnose and find. And with an uninitialized variable you get something that works now and then not, from time to time, with unpredictable consequences. Actually it's rather strange that I explain such basics to you who pose as an experienced programmer.

Look, if you want to get a stable error, it is very simple to initialize the stack:

int main() {
    if (true)
        int init_stack[10000] {0};
}

Initializing memory from HIP is also a piece of cake. If we run into some representation trap, we will get a core dump at all.

Once again, if optimizers were very smart, they would equate default init with value init with insertion of initializing instructions by the compiler as needed yet in some C11, but alas. Nobody forces, if you don't want, make T val{}; Tired of explaining elementary things.

 
Vict:

Once again, if optimizers were very smart, they would equate default init with value init with compiler inserting initializing instructions as needed in some C11, but alas. Nobody forces, if you don't want it, make T val{}; Tired of explaining elementary things.

Because, as I understand it, C++ standard describes the rules very formally, without contextualization. I.e. initialization either always or never. For comparison, in C# you can declare a variable without initialization, but further in the code it must be necessarily initialized. That is, the compiler analyzes the code that follows and not only the current command. This is laid down in the language rules. But the standard does not provide for any analysis in C++. So if they force initialization, you will complain that I want to control and initialize everything myself! )

 
Alexey Navoykov:

Because the C++ standard, as I understand it, describes the rules very formally, without contextualization. I.e. initialization is either always or never. By comparison, in C# you can declare a variable without initialization, but further in the code it must be necessarily initialized. That is, the compiler analyzes the code that follows and not only the current command. This is laid down in the language rules. But the standard does not provide for any analysis in C++. So if they force initialization, you will complain that I want to control and initialize everything myself! )

It's just that there get tested solutions, and if it will work out of the box, often causing unnecessary overhead, then no one will include it. For example, they have prescribed in the standard a MUST for the compiler to make copy elision in c++17.

 

The topic is called "Bugs, bugs, questions".

Please, create a topic where you will discuss MQL vs C#,C++, and other things related to syntax, compilers and mental workouts.

You are littering the thread, and other questions and users' messages are drowning in your discussion.

They ask me where to ask a question - I am directed here and the answer is: "Uncle's are arguing for a hundred pages there, so I won't interfere, the rest is meaningless ...

 
const int DEFAULT_INT_VALUE   = 147;
input int thisIsAnInput       = DEFAULT_INT_VALUE;
'NoConstForInput.mq5' NoConstForInput.mq5 1 1
'DEFAULT_INT_VALUE' - constant expected NoConstForInput.mq5 13 33
1 errors, 0 warnings 2 1

Build 2361 and 2390

 
Alain Verleyen:
'NoConstForInput.mq5' NoConstForInput.mq5 1 1
'DEFAULT_INT_VALUE' - constant expected NoConstForInput.mq5 13 33
1 errors, 0 warnings 2 1

Build 2361 and 2390

#define  DEFAULT_INT_VALUE 147
 
Vict:

Look, if you want to get a stable error, initializing the stack is very easy:

Initializing memory from a HIP is also a piece of cake. If we run into some representation trap, we get a core dump altogether.

One last comment, please don't be angry at the moderators )).

I need to clarify why the stack has different values from call to call. It's all about protecting https://ru.wikipedia.org/wiki/ASLR, and you don't even need to inanalyse anything at all, as I said earlier. In my case - I run the software under gdb (debugger), which will place it at the same address each time it is run, i.e. the stack will not be contaminated by "random" return addresses.

Reason: