Errors, bugs, questions - page 1837

 
fxsaber:
That's zero.

Yes, got it. Indeed, how can there be an order with TRADE_TRANSACTION_DEAL_ADD...

Thank you.

 
sizeof-bug
void f( uchar &Array[] )
{
  Print(sizeof(Array));
}

void OnStart( void )
{
  uchar Bytes[1];
  
  Print(sizeof(Bytes));
  
  f(Bytes);
}

Result
1
52
 

During testing, the log does not indicate the time at which the order expires:

2017.03.30 22:12:30.271 Core 1 2017.01.18 16:55:00 buy limit 0.01 EURUSD at 1.06789 (1.06879 / 1.06889 / 1.06889)<br / translate="no">2017.03.30 22:12:30.271 Core 1 order expired [#4 buy limit 0.01 EURUSD at 1.06789]

I would like it to be like this:

2017.03.30 22:12:30.271 Core 1 2017.01.18 17:25:00 order expired [#4 buy limit 0.01 EURUSD at 1.06789]

 
fxsaber:
sizeof-bug
Result

A local array of 1 byte has become a universal array object when passed as a parameter. The object buffer pointer is actually associated with the local array. but it cannot be redistributed.

The f function can take any array as an input, including a dynamic array.

 
Slawa:

A local array of 1 byte has become a universal array object when passed as a parameter. Its buffer pointer is actually associated with the local array. but it cannot be redistributed.

The function f can input any array, including dynamic

This is a very interesting explanation of the internal architecture. But because of this, sizeof produces quite a different result than what you expect when you code.

I.e. there is some inconsistency in documentation and it becomes unclear how to code without checking every time.


Moreover, if sizeof is called after the function exits, the size is determined without being affected by such nuances.

 

The option to synchronize positions without warning does not work and execute within spreads does not work either,
It opens at the worst price and cannot be adjusted, and so on all terminals. All the positions are opened.

What to wait for when the provider closes all the plus trades!

 
fxsaber:

This is a very interesting explanation of the internal architecture. But because of this sizeof gives out completely different things from what you intend when you code.

I.e. there is some inconsistency in documentation and it becomes unclear how to code without checking every time.


Moreover, if you call sizeof after exiting a function, the size is determined without being affected by such nuances.

Have you read the documentation about sizeof attentively?

The operation of taking the size of a data type or the size of an object of any data type ( sizeof )

With the help ofsizeofoperation it is possible to determine the size of memory which corresponds to an identifier or a type. The sizeof operation has the following format:

Example:

sizeof(expression).

Any identifier or a type name enclosed in brackets can be used as an expression. Note that a void type name cannot be used, and an identifier cannot refer to a bit field or be a function name.

If a static array name is specified as an expression (that is, the first dimensionality is specified), the result is the size of the entire array (i.e., the product of the number of elements by the length of the type). If a dynamic array name is specified as an expression (the first dimensionality is not specified), the result is the size of the dynamic array object.

When sizeof is applied to a structure or class type name or to an identifier that has a structure or class type, the result is the actual size of the structure or class.

PS there are more direct ways to find out the size of an array

 
Slawa:

If a static array name is specified as an expression (i.e. the first dimension is specified), the result is the size of the whole array (i.e. the product of the number of elements by the length of the type).

I left out of the quote only the piece that refers to the above code. It's a static array there, and the product of two numbers you mention should be equal to one.

If after passing the array from static becomes dynamic and on return it becomes static again, then how do you pass the array in static form then?

PS there are more direct ways to find out the size of the array

sizeof is good because of its universality - applicable to common types and arrays as well. And ArraySize is applicable only to arrays.
 
fxsaber:

From the quote, I left only the piece that refers to the above code. It's a static array, and the product of two numbers you mentioned should be one.


Once again. Where a static array is, it shows one.

The function parameters were never static arrays. There is an object of an unknown array beforehand. Dynamic, static, time series, indicator buffer

How does "universality of sizeof" help you? This is not C or C++ with direct access to memory. And you have to be careful when interpreting sizeof results. Allocate a dynamic array to 1000 elements and ask for sizeof. I'm talking specifically about C++ - you seem to be surprised at the result

And you haven't heard anything about _countof?

 
Slawa:

Once again. Where a static array is, it shows one.

The function parameters have never been static arrays. There is an object of an unknown array beforehand. Dynamic, static, time series, indicator buffer.

How does "universality of sizeof" help you? This is not C or C++ with direct memory access. And you have to be careful when interpreting sizeof results. Allocate a dynamic array to 1000 elements and ask for sizeof. I'm talking specifically about C++ - you seem to be surprised at the result

And you haven't heard anything about _countof?

I only know a little bit of MQL. I don't know SI, that's why I haven't heard.

void OnStart( void )
{
  uchar Bytes[];
  
  ArrayResize(Bytes, 100);
  
  Print(sizeof(Bytes));
}

The result is 52. Is it OK? I don't have any complaints about the internal architecture. I just want to make sure that my perceptions while coding are not mistaken. Notions are formed based on careful reading of documentation and test scripts for ambiguities.


In this case I have encountered some strange behavior in a large code. And after a long research I found a nuance described by you, which is unlikely obvious to anyone on this forum. And with the sample above it turns out that you cannot do sizeof for dynamic arrays at all (the result is always 52).

Reason: