Errors, bugs, questions - page 2761

 
Aleksey Mavrin:

0xFF is probably turned into 4 bytes by the compiler.

no, but it initialises correctly

uchar uc[16];
ArrayInitialize(uc,(uchar)0xFF); // truncation of constant value        
ArrayPrint(uc);                  //     255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
 

Good afternoon, please advise how to solve the problem:

During optimization an error pops up:

2020.05.31 15:05:32.738 Core 7 genetic pass (0, 53) tested with error "critical runtime error 503 in OnTick function (zero divide, module Experts\e1.ex5, file e1.mq5, line 826, col 73)" in 0:00:00.153

double Mix1 = NormalizeDouble((MathAbs(ZExtLevel[0] - ZExtLevel[1]), 2)

double Mix2 = NormalizeDouble((MathAbs(ZExtLevel[1] - ZExtLevel[2])), 2);

double Mix = NormalizeDouble((Mix1/Mix2),2);

What I did:

1) I multiplied Mix1 and Mix2 to reduce number of decimal places;

2) changed quantity of digits in normalization;

3) Checked all ZExtLevels to make sure they do not contain 0.


 
Igor Makanu:

No, but it initialises correctly

Why are you sure it doesn't? The default in Integer is to present. sizeof says so.

 
Aleksey Mavrin:

Why are you sure it doesn't? The default in Integer is to present. sizeof says it does.

uint, to be precise.

 
Aleksey Mavrin:

Why are you sure it doesn't? The default in Integer is to present. sizeof says so.


does it also work without any warnings?

char c[16];
ArrayInitialize(c, 127);

Because there is a corresponding signatureArrayInitialize

int  ArrayInitialize(
   char    array[],     // инициализируемый массив
   char    value        // значение, которое будет установлено
   );

and for some unknown reason they didn't create ArrayInitialize() for unsigned uchar

 
Igor Makanu:

works the same way without any warnings?

because there is a corresponding signature ArrayInitialize

and for an unsigned uchar they did not do ArrayInitialize() for some unknown reason.

It's not about the signature or absence of it. The point is that 4 bytes are converted into 1 and information can theoretically be lost - this is what the compiler warns about.

TryArrayInitialize(c, (char)10000);

there will also be a warning

 
Aleksey Mavrin:

It's not about the signature or lack thereof. The point is that 4 bytes are converted to 1, information can theoretically be lost which is what the compiler warns about.

TryArrayInitialize(c, (char)10000);

there will also be a warning

Well, it was clear from the very beginning

The question is here in a different way - where do you really need char?

I use uchar in StringToCharArray() and CryptEncode() and if you look through the help you'll find more

that's why I can initialize a char array using ArrayInitialize, but uchar I cannot do it


ok, that's a great hullabaloo, I doubt it will change ;)


PS: 0xFF = 255 (1 byte)

 
Igor Makanu:

yes it's clear that was all from the beginning

here the question is different, this is where char is really needed?

I use uchar in StringToCharArray () and CryptEncode (), and if you go through the help there are still

so that's why i can initialize a char array using ArrayInitialize, but uchar can't


ok, the noble holivar turned out, I doubt that something will change;)


PS: 0xFF = 255 (1 byte)

ArrayInitialize (uc,(char) 0xFF ); // truncation of constant value        
 
Igor Makanu:

Yeah, that's what it was all about from the beginning.

Here's another question. Where do you really need char?

I use uchar in StringToCharArray() and CryptEncode().

that's why I can initialize a char array using ArrayInitialize, but uchar I cannot do it

ok, that's a great hullabaloo, I doubt it will change ;)

PS: 0xFF = 255 (1 byte)

I don't know why you can't. uchar works the same way as char.

You asked why you got the warning, because 4 bytes in 1. 255 is not important. 0 and 1 can be 1 and 2 and 4 and 8 bytes)

 

Alain Verleyen:

ArrayInitialize (uc,(char) 0xFF );

checked:

uchar uc[16];
ArrayInitialize (uc, (char) 0xFF );
ArrayPrint(uc); 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255

OK, works without any compiler warnings

Thank you