Errors, bugs, questions - page 2760

 
Sergey Dzyublik:

The code shows a BAG where a condition cannot be entered, but still triggers a breakpoint in a completely different place in the code.
More questions?

The code optimizer threw everything away and the function is left empty.

The breakpoint moved to the very end of the function and triggered.

 
MetaQuotes:

It was the code optimiser that threw everything out and left the function empty.
The breakpoint moved to the same end of the function and worked.

I got a little excited with the first example, I agree.
But what about the second one? Well, the breakpoint remains inside the condition and does not move anywhere.
The triggering of a breakpoint misleads the user into thinking that the input condition has been met, when in fact it might not be so at all:

class A{
public:
   bool m_flag;
   A* m_next;
   A(bool flag) : m_flag(flag){}
   
   void test(){
      if(m_flag){
         printf("1");
         m_next = m_next;    // Вручную установленная точка останова срабатывает как для false так и true условий
         //m_next = &this;   // Ok
      }   
   }
};

void OnStart(){
  {A a(false); a.test();}   // Result: breakpoint              Expected result: 
  {A a(true);  a.test();}   // Result: printf + breakpoint     Expected result: printf + breakpoint
}
 
MetaQuotes:

The breakpoint moved to the same end of the function and worked.

Do you think this is not a bug?

 
MT5 (build 2460) something broke when using inheritance from template classes, in previous versions including build 2450 everything worked.
 
MT5 bug (build 2460) compilation error when inheriting from template class from namespace.
C++ online:https://onlinegdb.com/S1E503pj8
namespace NameSpace{  
   struct A{};
   
   template<typename T>
   struct B : public A{};          // 'A' - declaration without type
};

struct D : public NameSpace::B<int>{
   int data;
};

void OnStart(){
   D d;
}
 

Forum on trading, automated trading systems and strategy testing

OOP questions in MQL5

fxsaber, 2020.05.30 10:04

Got an unexpected result.
#include <fxsaber\Benchmark.mqh> // https://c.mql5.com/3/321/Benchmark.mqh

// Простая структура.
struct STRUCT1
{
  int i;  
  double j[2];
};

// Сложная структура.
struct STRUCT2
{
  int i;  
  string Str;
  
  STRUCT2() : Str("1234567 1234567")
  {
  }
};

template <typename T>
int Func( T &Array[] )
{  
  // Write
  for (int i = ArraySize(Array) - 1; i >= 0; i--)
    Array[i].i = i;

  int Sum = 0;
  
  // Read
  for (int i = ArraySize(Array) - 1; i >= 0; i--)
    Sum += Array[i].i;
    
  return(Sum + ArraySize(Array));    
}

void OnStart()
{
  STRUCT1 Array1[]; // Простая структура.
  STRUCT2 Array2[]; // Сложная структура.
  
  const int Amount = 5 e7;
  
  Print(_B(ArrayResize(Array1, Amount), 1));
  Print(_B(ArrayResize(Array2, Amount), 1));
    
  Print(_B(Func(Array1), 1)); // Чтение и запись простой структуры происходит в разы дольше,
  Print(_B(Func(Array2), 1)); // чем сложной.
}


        50000000
        Alert: Time[Test6.mq5 280: ArrayResize(Array2,Amount)] = 640 ms.
        50000000
        Alert: Time[Test6.mq5 282: Func(Array1)] = 440 ms.
        1333106752
        Alert: Time[Test6.mq5 283: Func(Array2)] = 156 ms.
        1333106752
 

Why inOBJ_TRENDBYANGLE we can't know the angle programmatically?

We can set the time and prices of the two points programmatically, but the angle returns 0.

If we move OBJ_TRENDBYANGLE manually, the normal angle value is returned.


I want to simply place text on the trendline at the same angle as the trendline itself.

But the trendline does not return the angle, while OBJ_TRENDBYANGLE has a fixed second coordinate and when the chart scale changes as a result of rise or fall in price, we get false information...

 

Why does the compiler give a warning ?

uchar uc[16];
ArrayInitialize(uc, 0xFF); //truncation of constant value

UPD: no

int ArrayInitialize( uchar array[], uchar value );

it is not convenient to write

uchar uc[16] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
 

401code - what is the error ?

what's up?

401

Inheritance from this class is impossible because it is declared with specifier final

Документация по MQL5: Основы языка / Типы данных / Структуры, классы и интерфейсы
Документация по MQL5: Основы языка / Типы данных / Структуры, классы и интерфейсы
  • www.mql5.com
Структура является набором элементов произвольного типа (кроме типа void). Таким образом, структура объединяет логически связанные данные разных типов. Объявление структуры Имя структуры нельзя использовать в качестве идентификатора (имени переменной или функции). Следует иметь ввиду, что в MQL5 элементы структуры следуют непосредственно друг...
 
Igor Makanu:

Why does the compiler give a warning ?

UPD: no

int ArrayInitialize( uchar array[], uchar value );

is not convenient to write

0xFF is probably turned into 4 bytes by the compiler.

Alexsandr San:

401code ,can someone tell me what is this error ?

found

401

Inheritance from this class is impossible because it is declared with specifier final

What's the question - there is no final modifier, but there is an error, or what?