Errors, bugs, questions - page 3020

 
A100:

If it is initialised, then why does the execution

error 4009

ERR_NOTINITIALIZED_STRING

4009

Uninitialized string

This is a matter of terminology.

 
mktr8591:

That's not the problem, it's the fact that this code returns 4 and should return 0.

This just means that -1 and 0 have the same result. The same result will probably give INT_MAX and something else.

Knowing/knowing some of the features of the regular functions is fine.
 
fxsaber:


It's ok to know/know some features of regular functions.

Of course. Especially when the feature is a bug ))

Well and unequivocally add to the branch"Features of mql5language..."

 
fxsaber:

It just means that -1 and 0 have the same result.

If you think this is logical and correct, I think it makes you wonder if your logic is logical

 
const string text[] = { "ABC", "", "ABC" };    
uchar array[];
    
int start = 0;
int n     = 0;
    
for(int i=0; i < ArraySize(text); i++)
{
   const int count = StringLen(text[i])+1;
   Print(count);
        
   n += StringToCharArray(text[i], array, start, count);
   start += count;
}
    
Print(ArraySize(array), ":", n );
2021.05.24 22:56:35.959 Test (AUDUSD,M5) 4
2021.05.24 22:56:35.959 Test (AUDUSD,M5) 1
2021.05.24 22:56:35.959 Test (AUDUSD,M5) 4
2021.05.24 22:56:35.959 Test (AUDUSD,M5) 9:9
 
mktr8591:

Of course. Especially when the feature is a bug ))

Well and definitely add to the branch"Peculiarities of mql5language...".

Tweak documentation a bit and it's no longer a bug.

Andrei Trukhanovich:

If you think it is logical and correct, I think this is a reason to think about the logic of your logic.

Philosophy is far from practice.

 
Roman:

+1 is unnecessary because a clean copy (without terminating null characters) is required. If you want to prove it is not a bug, you need arguments

 
A100:

requires a clean copy (no terminating null characters)

if (StringLen(text[i]))
  start += StringToCharArray(text[i], array, start, StringLen(text[i]));

This is a very bearded design.


WZ

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

const string text[] = { "ABC", "", "ABC" }; 

void OnStart()
{
  ArrayPrint(_R(text).Bytes); // Побайтовое представление массива.
  
  string Str;  
  _W(Str) = text;
  
  ArrayPrint(_R(Str).Bytes); // Побайтовое представление объединенной строки.
}
 
fxsaber:

Tweak the documentation a bit and it's no longer a bug.

Philosophy is far from practice.

And how will the practitioner explain such a contradictory result to the theorists:

void OnStart()
{
    string text = "ABC";
    const int start = 0, count = 0;
    uchar array1[]; int n1 = StringToCharArray(  text, array1, start, count );
    short array2[]; int n2 = StringToShortArray( text, array2, start, count );
    Print( n1, ":", n2 );
}

Result: 4:0

Expectation: 0:0

Or will they correct documentation a bit too? Well, not to fix bugs after all!

My explanation is simple: there is a bug in one of these standard functions - and I even know which one

 
A100:

And how would a practitioner explain such a result to a theorist?

My explanation is simple: one of these functions has a bug - and I even know which one.

The bug is a discrepancy between these two functions, not their result, because it's just a matter of documentation what to output when count=0.