Errors, bugs, questions - page 2703

 
template <typename T>
int CMapManager::IncreaseArraySize( T &array[] )
{

}

Shouldn't there be an error when compiling this code that the function should return a value?

 
Alexey Kozitsyn:

Shouldn't there be an error when compiling this code that the function should return a value?

it should

Most likely, you didn't access this method and the compiler didn't include this part of the code in the executable file

 
Igor Makanu:

should

Most likely, you haven't accessed this method and the compiler hasn't included this code fragment into the executable file.

But if I designate the Test() function in the same class and implement it that way:

int CMapManager::Test()
{
        
}

The error will occur, although I haven't accessed this function anywhere either.

 
Alexey Kozitsyn:

But if I designate Test() function in the same class and implement it this way:

An error will occur, even though I haven't accessed this function anywhere either.

because this method is not a template - there is no template

a template is essentially a macro substitution, in which the compiler inserts the necessary types when detecting calls of functions(class methods)

this "substitution" will "generate" functions with specific data types

this is approximately how it works

 
Igor Makanu:

because this method is not a template - there is no template

a template is essentially a macro substitution, in which the compiler will substitute the necessary types when detecting function(class method) calls

this "substitution" will "generate" functions with specific data types

this is approximately how it works

That's roughly how I see it, thank you. But the question is why at the stage "before the generation" we shouldn't inform that the int value should be returned?

After all, regardless of the generated functions, all of them will return a value of int type.

 
Alexey Kozitsyn:

That's roughly how I see it, thank you. But, the question is different, why at the stage "before generation" don't we inform that we need to return int value?

After all, regardless of generated functions, all of them will return a value of int type.

You and I have gone for the second run - we will give the same answers to the same question )))

no call - no pattern application, that's it - that's how it works

)))

sketch the script and try it out

like this:

template <typename T>
T add(T a, T b)
{
  // return(a+b);
}
//+------------------------------------------------------------------+
void OnStart()
{
   Print("start");
  // Print(add(1.0 , 2.0));

}

it compiles like this, then open your comments - there will be errors

 

I missed something somewhere, in general I am looking for a catch in such a code:

struct SMatrix
{
   SMatrix(){}
   SMatrix(int rows,int cols){ ArrayResize(this.ROW,rows); for(int i=0;i<rows; i++) ArrayResize(this.ROW[i].COL,cols); }
   struct SRow{float COL[];};
   SRow ROW[];
};

//+------------------------------------------------------------------+
void OnStart()
{
   SMatrix matrixA(10,2);
   int count = 0;
   for(int i = 0;i<10;i++)
   {
      for(int j=0;j<2;j++) matrixA.ROW[i].COL[j] = (float)count++; 
   }
   
   SMatrix matrixB = matrixA;
   for(int i=0;i<10;i++)
   {
      ArrayPrint(matrixB.ROW[i].COL);
   }
}

2020.04.12 01:40:16.652 tst (EURUSD,H1) 0.00000 1.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 2.00000 3.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 4.00000 5.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 6.00000 7.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 8.00000 9.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 10.00000 11.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 12.00000 13.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 14.00000 15.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 16.00000 17.00000

2020.04.12 01:40:16.652 tst (EURUSD,H1) 18.00000 19.00000


it's confusing that it's so easy to create a two-dimensional array and assignment without copy constructor description works out of the box

what in my code may not work correctly?

 

NO DECOMPILING ALLOWED!

 

Just in case, is there any way to make theStringToCharArray function copy bytes without conversions? Tried all CP_XXX, none of them provide 1-to-1 copies in general case. Here's an example:

void OnStart()
{
  uchar buffer[];
  string data = " test";
  StringSetCharacter(data, 0, 0x81); // just an example, can be obtained in other ways
  StringToCharArray(data, buffer);
  // buffer[0] = (uchar)data[0];     // correct/direct copy
  ArrayPrint(buffer);
}

The way to get 0x81 byte can be different, here it's set "head-on" for simplicity. If you don't use manual byte-by-by-byte copying (as in the unmentioned line), the StringToCharArray function converts byte 129 (0x81) to 63.

So far I had to replace StringToCharArray with a loop, but maybe there is a secret CP_XXX?

 
Stanislav Korotky:

Just in case, is there any way to make the StringToCharArray function copy bytes without conversions? Tried all CP_XXX, none of them provide 1-to-1 copies in general case. Here's an example:

The way to get 0x81 byte can be different, here it's set "head-on" for simplicity. If you don't use manual byte-by-by-byte copying (as in the unmentioned line), the StringToCharArray function converts byte 129 (0x81) to 63.

I had to replace StringToCharArray with a loop for now, but maybe there is a secret CP_XXX?

void OnStart()
{
   uchar buffer[];
   string data = CharToString(0x81) + " test";
   StringToCharArray(data, buffer,0,StringLen(data));
   ArrayPrint(buffer);
}

2020.04.12 15:57:37.812 tst1 (EURUSD,H1) 129 32 116 101 115 116

Reason: