Errors, bugs, questions - page 3021

 
fxsaber:

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

No, there is also such a thing as uniformity principle. the bug is obvious. if you don't understand why it is a bug, that's your problem.

 
fxsaber:

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

Forum on trading, automated trading systems and strategy testing

Errors, Bugs, Questions

Roman, 2021.05.07 22:07

The whole trick is in the function description ))

[in]  Количество элементов массива для копирования. Определяет длину результатной строки. 
По умолчанию -1, что означает копирование до конца массива, либо до встречи терминального 0. 
Терминальный 0 также будет скопирован в массив-приемник, 
при этом размер динамического массива может быть увеличен при необходимости под размер строки. 
Если размер динамического массива больше длины строки, то размер массива уменьшен не будет. 

automatic progress ))
what confuses the user more.

A100:

And how would a practitioner explain such a contradictory result to theorists?

Result: 4:0

Expected result: 0:0

Or also - to correct documentation a bit? Well, not to fix bugs after all!

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


 
Roman:

After that the Developers have alreadycorrected, so your previous explanation is no good

The functions are the same (differ only in type, in fact the template), the description is the same (there are even cross-references), but the result is different

 
A100:

The Developers have already fixed it, so your previous explanation does not work

What exactly has been fixed?
It's always been like it is in the documentation.

str1

str1


Did you check what was fixed? ))
Fixed, split as you wanted.
3 characters, for example.

char ch[];
int str = StringToCharArray( "ABCDEF", ch, 0, 3 );
    
Print("StringToCharArray "+(string)str);
Print("ch[] ",CharToString(ch[0]), CharToString(ch[1]), CharToString(ch[2]));
Print("GetLastError ", GetLastError());         

2021.05.25 02:08:33.329 Test (AUDUSD,M1)   StringToCharArray 3
2021.05.25 02:08:33.329 Test (AUDUSD,M1)   ch[] ABC
2021.05.25 02:08:33.329 Test (AUDUSD,M1)   GetLastError 0

But if you pass 0 into count, the entire string with an ending zero will be copied automatically.
Even if the string is empty, an ending zero will be copied.

char ch[];
int str = StringToCharArray( "", ch, 0, 0 );
    
Print("StringToCharArray "+(string)str);
2021.05.25 02:24:47.161 Test (AUDUSD,M1)   StringToCharArray 1
And StringLen() does not return a terminating zero ))
 
Roman:

What exactly did you fix?

But if you pass 0 to count, the whole string with an ending zero will be copied automatically.
Even if the string is empty, the ending zero will be copied.

Why is it different inStringToShortArray? Please briefly explain without unnecessary cunning and inexplicable references to your earlier brilliant explanations (which failed in the end) - in simple terms - for a dummie

without ; ) and other inappropriate symbols in this topic.

 
A100:

Why is it different inStringToShortArray? Please explain in brief, if possible, without any tricks and incomprehensible references to your earlier brilliant explanations (which failed in the end) - in simple terms - for a dummie

without ; ) and other irrelevant symbols in this topic.

Split works

ushort sh[];
int str = StringToShortArray( "ABCDEF", sh, 0, 3 );
    
Print("StringToShortArray "+(string)str);
Print("sh[] ",ShortToString(sh[0]), ShortToString(sh[1]), ShortToString(sh[2]));
Print("GetLastError ", GetLastError()); 
2021.05.25 03:10:07.696 Test (AUDUSD,M1)   StringToShortArray 3
2021.05.25 03:10:07.696 Test (AUDUSD,M1)   sh[] ABC
2021.05.25 03:10:07.696 Test (AUDUSD,M1)   GetLastError 0

I don't know why count 0 doesn't work.
Maybe this smart automatic on count 0 does not work here, and according to the help, it already is a mismatch.
And it must be an error.

ushort sh[];
int str = StringToShortArray( "ABCDEF", sh, 0, 0 );
    
Print("StringToShortArray "+(string)str);
//Print("sh[] ",ShortToString(sh[0]), ShortToString(sh[1]), ShortToString(sh[2]));
Print("GetLastError ", GetLastError()); 
2021.05.25 03:12:00.176 Test (AUDUSD,M1)   StringToShortArray 0
2021.05.25 03:12:00.176 Test (AUDUSD,M1)   GetLastError 0

Anyway, either there is an error here thatdoes not work oncount 0,
or there is an error in StringToCharArray that
worksoncount 0.

To make you understand the soundness of explanations, study the basics of the C language, especially handling strings.
Then there will be no questions.

 
Roman:

In short, either there's an error here that count 0 doesn't work,
or there's an error in StringToCharArray that count 0 does work.

Brilliant!

 
A100:

Brilliant!

Of course it's genius. The help doesn't explicitly disclose handling ofcount 0.
But if you turn your head, passing a zero size to the array and allocating zero memory to it is strange, to put it mildly.
That's whycount 0 triggers automatic resizing to the end of the string.
By logic, it should work in StringToShortArray as well.
The error would have been returned better, without any resizing.
 
Roman:
Of course it's genius. Help does not explicitly disclose handling ofcount 0.
But if you turn your head, passing a zero array size and allocating zero memory to it is strange, to put it mildly.
That's why count 0 triggers automatic resizing to the end of the string.
By logic, it should work in StringToShortArray as well.
They'd better return an error without any resizing.

And in

CharArrayToString

Why not all the way to the end?

void OnStart()
{
    const uchar array[] = { 'A', 'B', 'C' };
    const int start = 0, count = 0;
    Print(CharArrayToString( array, start, count ));
}

Result: ""

 
A100:

And in

Why not all the way to the end?

Result: ""

Probably because there is no [out] dynamic array inCharArrayToString.
And the developer decided that this was unnecessary.
Although different logic in similar functions causes more confusion.

Reason: