Features of the mql5 language, subtleties and tricks - page 148

 

can you tell me why the compiler started swearing at this (screenshots attached)?

a year ago everything was ok, but now I put the latest terminal, compile and this

where can i find answers to these messages?

and how to correctly resolve this warning?

upd. added 3rd screenshot - same message on innocuous code

and 4th screenshot

what's the strictness of the compiler and how to solve it?

Компиляция - Разработка программ - Справка по MetaEditor
Компиляция - Разработка программ - Справка по MetaEditor
  • www.metatrader5.com
Компиляция — это процесс перевода исходного кода MQL4/MQL5-программы на машинный язык. Ее результатом является создание исполняемого файла программы (*EX4 или *.EX5), который может быть запущен в торговой платформе. Скомпилировать можно любой файл (*.MQ4, *.MQ5 или *.MQH), однако исполняемый файл (*.EX4 или *.EX5) может быть получен только в...
Files:
22.png  6 kb
3.png  4 kb
4.png  5 kb
 
/+------------------------------------------------------------------+
TT
class cl_search_: public cl_search_b<T>
  {
#define  ME cl_search_<T>
#define  THIS &this
public:
   atype             adres;lin;//Ошибка тут компилятор молчит
   ME               *m[2],*par;
   atype Adress()                            {return par==NULL? adres :(adres|(par.m[1]==THIS? (par.lin^(par.lin<<1))>>1: 0)|par.Adress()); }
   string AdressStrBit(int move=0)           {return  "|| "+IntToBitString(adres)+" "+(string)lin+(par==NULL? "\n": ((" "+(string)(par.m[1]==THIS ?(par.lin^(par.lin<<1))>>1 :0))+" \n"+(par.AdressStrBit())));}
   string IntToBitString(atype s=0)          {if(s==0) {s=adres;} string itog ="W"; atype a=1; uchar ss=sizeof(atype)*8; for (char i=ss-1; i>=0; i--) itog+=(string)(uint)((s&a<<i)>0); return itog;}
   void CorrectPar()                         {if(m[0]!=NULL) m[0].par=THIS; if(m[1]!=NULL) m[1].par=THIS;}

   ME *Select(bool next=true) {return par==NULL ?  par:((par.m[next]==THIS || par.m[next]==NULL) ?  par.Select(next) :par.m[next].Start(!next)); }
   
   
   ME *Port(atype a,bool write=true)
     {
#define  PORT(A) Port(A&linre,write)
#define  NEW new ME(THIS)
      if(m[1]==NULL && m[0]==NULL)
        {
         if(!write) return NULL;
         //lin=(~(atype)0)<<1;
          adres=a&lin;
         return m[a&1]=NEW;
        }
      atype h111=(lin&a)^adres;
      atype linre=(~lin)>>1;
      if(h111==0)
fxsaber
:

I encountered such a peculiarity.


If during definition of a class with static fields its object is created immediately, there will be a compilation error.

In the last version, the compiler did not complain about the variable without type in the class. But the EA crashed on startup

 

I stumbled across a "feature"... I spent over an hour translating the indicator from 4 to 5. i couldn't figure out where the error was, as the code seemed to be cross-platform. in the end, here it is, an inconspicuous place. for some reason they swapped two parameters:

improvement?

are there more of these?

 
are there more of these?
StringTrimLeft / Right

StringConcatenate

there's probably more, I'm also interested in a complete list of such functions

---

it might be worth searching for #endif in the standard library

 
// Альтернативное создание папки.
bool FolderCreate2( const string FolderName, const int CommonFlag = 0 )
{
  return(FileOpen(FolderName + "\\", FILE_WRITE | (CommonFlag ? FILE_COMMON : 0)) == INVALID_HANDLE);
}
 
In fours it was possible to call the indicator itself via iCustom to get a multitimeframe. Can you share a link/example for five? For some reason I can't do it by analogy :(
 

But the battle councillor ran into a situation where the councillor stopped working. Managed to get to the bottom of the cause. A cool nuance, which is almost impossible to notice.

You can really get a feel for it by trying to see the problem in this code.

// В коде содержится ошибка, которая остановит выполнение этого советника.

input int Range = 0;

class A
{
public:
  void f() {}
};

A* const a = new A;

void OnInit() { a.f(); }

void OnDeinit( const int ) { delete a; }
 
fxsaber:

But the battle councillor ran into a situation where the councillor stopped working. Managed to get to the bottom of the cause. A cool nuance, which is almost impossible to notice.

You can really get a feel for it by trying to see the problem in this code.

One of the main rules is that at what level you construct an object, you must destruct it at the same level. Not higher or lower.
 
Slava:
One of the main rules is that at what level you construct an object, at the same level you need to destruct it. Not higher or lower.

Thank you, good rule. Became a victim of my own incompetence. Really, need some more rule for such a more obvious case.

// В коде содержится ошибка, которая остановит выполнение этого советника.

input int Range = 0;

class A
{
  void f() {}
public:
  A()
  {
    static A* Tmp = &this;
    
    Tmp.f();
  }
};

void OnInit() { A a; }


Maybe for both cases Warning clever to do?

 
fxsaber:

But the battle councillor ran into a situation where the councillor stopped working. Managed to get to the bottom of the cause. A cool nuance, which is almost impossible to notice.

You can really get a feel for it by trying to see the problem in this code.

What is the problem with this code? Deinit nailed the object by constant pointer (I know what the handle is here). Normal limb-shooting in C++ style, or else the creators have dissolved everyone)))
Reason: