Errors, bugs, questions - page 167

 

Question about dynamic arrays

double open_main_array[] - class variable

initialization

ArraySetAsSeries(open_main_array,true);

The 1st call of the function which contains the following code

CopyOpen(Symbol(), PERIOD_M15, 0, Count, open_main_array);

2nd call of the function

CopyOpen(Symbol(), PERIOD_M15, 0, Count, open_main_array);

Will the open_main_array array contain data copied during the 2nd call or the array will be incremented and contain data from the 1st and 2nd calls?

Alternatively, you can use:

ArrayFree(open_main_array)

CopyOpen(Symbol(), PERIOD_M15, 0, Count, open_main_array);

Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 
Renat:

uninitialized variable - means that the variable is guaranteed to have a pass-through branch when it is uninitialized. for example, default is explicitly omitted in switch, in which MainPrice should be explicitly initialized (or explicitly zeroed out when declared).

About "guaranteed pass". Here's such a piece of code:

            (1)         double local_low;
            (2)         uint index_interior=i-k;
            (3)         bool interrupcion=false;
            (4)         for(uint n=1;n<Ac-k;n++)
            (5)           {
            (6)            if(low[index_interior-n]<low[index_interior-n-1])
            (7)              {
            (8)               local_low=low[index_interior-n];
            (9)               interrupcion=true;
            (10)              break;
            (11)              }
            (12)          }  
            (13)        if(interrupcion)
            (14)          {
            (15)           if(EspacioFalladoPlus0<high[index_interior]-local_low)
                       ...

For the last line (line 15) it says "possible use of uninitialized variable 'local_low'".

But because of using bool-variable interrupcion in line 9 right after initializing variable local_low in line 8, it turns out that in line 15 variable local_low will be guaranteed initialized. So at this point, the warning "possible use of uninitialized variable 'local_low'" does not mean "guaranteed", but only possible presence of a pass-through branch in which the variable is uninitialized.

 
Yedelkin:

About "guaranteed passage". Here's a piece of code:

For the last line (line 15) it says "possible use of uninitialized variable 'local_low'".

But because of using bool-variable interrupcion in line 9 right after initializing variable local_low in line 8, it turns out that in line 15 variable local_low will be guaranteed initialized. So at this moment the warning "possible use of uninitialized variable 'local_low'" does not mean "guaranteed" but just possible presence of a pass-through branch where the variable is uninitialized.

That's exactly right, it gives you a warning.

Don't confuse your complacency with reality. Reality is revealed after many projects and understanding that 'this cannot be because logic leads so-and-so' happens every day.

 
Renat:

Do not confuse your self-confidence with reality. Reality is revealed after many projects and the realisation that "this cannot be because logic leads so-and-so" happens every day.

Can you get an adequate explanation? The code is given, the "self-righteous" statement is stated, where is the error? I do not understand esotericism.

...If you consider the translation of the phrase"possible use of uninitialized variable", the warning is indeed issued "absolutely correct". But it's not about "guaranteed", but just about possible existence of a branch of a pass where the variable is uninitialized. That is exactly what I am "confidently" talking about.

 
Yedelkin:

Can we get an adequate explanation? The code is given, the "self-righteous" statement is stated, where is the error? I don't understand esotericism.

What if instead of

interrupcion=true;

instead of (for example)...

interrupcion = (someFunction1(input) > someFunction2(input2)) && (someFunction3() < 1) || (someFunction1(input3) * someFunction3() > 10);
Would you make a claim too? Especially if someFunctionN consists of hundreds of lines of code?

According to your piece of code, yes, the variable is initialized if line 15 is executed. But what would you tell the compiler to do in the example I gave? The task is hard. And there's no need in solving it either.

The error is called"possible (maybe) use of uninitialized variable" (although you know about it anyway).

You'd better explicitly assign some value to variable local_low. Believe me, it can save you from possible errors in the future (code is corrected, something is removed, something is moved, something is changed, and line 13 can fall out of this process)

 
Yedelkin:

Can we get an adequate explanation? The code is given, the "self-righteous" statement is stated, where is the error? I don't understand esotericism.

In the real world, when the vast majority of programmers in any language write completely unprotected and glitchy code, compilers should be made as rigorous as possible. Programmers' complacency "the logic is clear, there should be no problems, everything is initialized as it should be" brought and still brings and will bring in a great many errors.

That is why the questions on criticism of strict measures are irrelevant here.

 
Renat:

... The self-confidence of programmers "the logic is clear, there should be no problems, everything is initialized properly" has caused, brings and will bring a huge number of errors.

That's why criticism of strict measures is irrelevant here.

Let's do without criticism. All the more so, I did not put it in my words. And concerning the presence of criticism on my part you are deeply mistaken.

So, what is your error? Since you cannot put esotericism into a code, please answer me on the language of logic. That is, in a language that any programmer can understand.

 
notused:

would you make a claim too? Especially if someFunctionN consists of hundreds of lines of code?

You are in the same place too. Well, I don't have any complaints. I just want to make it clear that everything is not as categorical as Renat says.

What about the code. I gave you a specific example of code that disproves categoricalness of Renat's statement using ordinary logic. Thanks for the advice, I'm trying to improve all the time.

 
Yedelkin:

Let's dispense with the criticism. Especially since I did not put it in my words. And as for the existence of criticism on my part, you are deeply mistaken.

So, what's your mistake? Since you cannot put esotericism into a code, please answer me on the language of logic. That is, in a language any programmer can understand.

You have"possible use of uninitialized variable 'local_low'".

And what do you get if

(1)         double local_low=1.1; // или что-то другое
 
Yedelkin:

So, what is a mistake? Since you cannot put esotericism into the code, please answer in the language of logic. That is, in a language any programmer can understand.

Re-read my answers from the point of view of a software company manager who has brought many software projects to market.

Otherwise, remaining at the level of "any programmer", you will not understand what the mistake is.

Reason: