Errors, bugs, questions - page 2520

 

And there is no mistake

Это_новая_форма_комментария;
void OnStart() {}
 

Error during compilation

void f() {} //Error: 'f' - function must have a body
void f();
void OnStart()
{
        f();
}

Otherwise:

void f() {}
void OnStart()
{
        f();
}

It's fine. What's the difference?

Besides, C++ compiles normally in one pass:

#ifdef __cplusplus
void f( int ) {}   //была функция
//...
void f( int = 1 ); //уточнили параметры по умолчанию
void OnStart()
{
        f();       //вызвали
}
#endif
 
And there is no compilation error... All that's left to do is guess the result:
int f( int     ) { return 1; }
//...
int f( int = 2 );
int f( int     ) { return 3; }
void OnStart()
{
        Print( f( 0 ));
}
 

Unclear warning on compilation

//lib.mqh //объявления
void f(); //Warning: no #import declaration
//lib.mq5 //реализация
void f() {}
//Test1.mq5 //собираем все вместе
#include "lib.mqh"
#include "lib.mq5"
void OnStart() { f(); }

Otherwise:

//Test2.mq5
void f();
void f() {}
void OnStart() { f(); }

everything's fine - there's no warning. What difference does it make?

 
A100:

Unclear warning during compilation

//lib.mqh //объявления
int f(); //Warning: no #import declaration

//lib.mq5 //реализация
void f() {}
A typo with the int type, I presume?
 
Alexey Navoykov:
It's a misprint with the int type, I suppose?

Yes... Corrected everywhere to void - for simplicity.

On the other hand, the meaning, but already warnings (*) are not clear

//lib.h //объявления
int g();  //Warning: no #import declaration //(*)
void f(); //Warning: no #import declaration
lib.h is a general declaration file, while lib.mq5, lib2.mq5, lib3.mq5... files with implementations, which are included by means of #include as needed. Thus, there may be no int g() implementation in a particular build at all, but the obscure warning is there. In fact, there are hundreds of them and they prevent you from seeing really important warnings
 
A100:

Yes... Corrected everywhere to void - for simplicity.

On the other hand, the meaning, but already warnings (*) are not clear

lib.h is a common file with declarations, while lib.mq5, lib2.mq5, lib3.mq5... files with implementations, that are plugged in via #include as needed. Thus, there may be no int g() implementation in a particular build at all, but the obscure warning is there. Actually there are hundreds of them, and they hamper the view of really important warnings.

Note that even if you specify an implementation in the same inclusion book, this warning will also pop up.

 

The following error deserves special attention:

//lib1.mqh
void f(); //Error: 'f' - function must have a body
#include "lib.mq5"
//...
//lib2.mqh
void f();
#include "lib.mq5"
//...
//lib.mq5
void f() {}
#include "lib1.mqh"
#include "lib2.mqh"
void OnStart()
{
        f();
}

Essentially similar to this one, but with many files, rather unobvious and difficult to understand

 
Can you tell me how C++ works with this?
struct A
{
  int i;
};

struct B : public A
{
  string Str;
};

void OnStart()
{
  A a = {0};
  B b;
  
  b = a; 
  a = b; // OK
}
I'm wondering whether to use this feature in my code or not. If it works in C++, I'll use it. No, I don't think so, because it may be cancelled in next builds.
 
Is it an error that there is no initialisation warning?
struct A
{
  int i;
};

struct B : public A
{
  string Str;
};

void OnStart()
{
  A a;
  B b;
  
//  b = a; // possible use of uninitialized variable 'a'
  a = b; // OK
}