Errors, bugs, questions - page 2502

 
fxsaber:

Couldn't quite figure it out yet.

Not from the order of the fields, but from the maximum and set value of pack() plus it depends on the order of the fields.

Now I have made the following variant

struct A pack(16)
{
  short   j;
  double  x;
  int     b;
};

void OnStart()
{
  Print(sizeof(A)); // 24
}

It aligns not to 16 as specified in pack(), but to 8 by the maximal double.

 
Alexey Viktorov:

plus it depends on the sequence of the fields.

checked, it does depend:

struct A pack(16)
{
  double  x;
  short   j;
  int     b;
};
//+------------------------------------------------------------------+
void OnStart()
  {
   Print(sizeof(A)); // 16
  }
//+------------------------------------------------------------------+
Your example gavesizeof(A) = 24
 
fxsaber:

So that's how this discussion started. It turns out that it's not like that at all.

Yes, I made a mistake in describing the alignment algorithm and thus may have caused even more confusion.

So,

pack is a compatibility mechanism with external dlls. In particular, it is analog of c++ #pragma pack and therefore should work in the same way.

further examples with dimensions (for pack 4)

char -> 1

short -> 2

int -> 4

long -> 8

char, short -> 4

char, int -> 8

char, long -> 12 (16 for pack(8))

short, char -> 4

long, char -> 12

long, char, short -> 12

long, char, char, char -> 12

long, char, int -> 16

long, char, int, char -> 20

studio (and probably everywhere else) defaults to pack(8)
 
TheXpert:

Thank you, I see.

 
Alexey Viktorov:

Everything works in my opinion. Since in your example there is only one type in the structure, there is no point in alignment.

You are mistaken, it does not work correctly. It does make sense. It's a bug. https://www.mql5.com/ru/forum/1111/page2498#comment_12349659

 

Hello. Can you please tell me if there are any hotkeys for trading in MT5? I have not found them in the manual. If not, is there any way to implement it? I.e. I pressed a key and an order opened, is there something similar?

 
Vict:

Wrong, it doesn't work right. It makes sense. It's a bug. https://www.mql5.com/ru/forum/1111/page2498#comment_12349659

So what's the bug?

struct A pack(4)
{
  short j;
};

void OnStart()
{
   A q[2];
   Print(sizeof(q)); // 4
   return;
}

You declare an array of two elements with two bytes each and get 4 bytes as it should be. Where's the bug? What?

This.

struct A pack(4)
{
  short j;
  int   b;
};

void OnStart()
{
   A q[2];
   Print(sizeof(q)); // 16
   return;
}

The array is aligned to 4 and 2 elements will take 2*8 bytes.

 
astronom55:

Hello. Can you please tell me if there are any hotkeys for trading in MT5? I have not found them in the manual. If not, is there any way to implement it? I.e., I pressed a key and an order opened, is there something similar?

Did the cat step on the keyboard and trade for you?

Do it yourself - it's not difficult.

 
astronom55:

Hello. Can you please tell me if there are any hotkeys for trading in MT5? I have not found them in the manual. If not, is there any way to implement it? I.e. I pressed a key and an order opened, is there something similar?

Terminal Help:Hotkeys - Advanced Users - Getting Started


If you need to take action "Just click once and a position is opened" - then a combination of keys should be assigned to a script or an Expert Advisor in the terminal (script or Expert Advisor should either be downloaded, written or ordered).

Горячие клавиши - Для продвинутых пользователей - MetaTrader 5
Горячие клавиши - Для продвинутых пользователей - MetaTrader 5
  • www.metatrader5.com
Горячие клавиши — это клавиши и их комбинации, которые позволяют быстро выполнять различные команды без обращения к меню и панелям управления. Существует возможность назначать горячие клавиши для вызова любого элемента окна "Навигатор", за исключением элементов группы "Счета". Чтобы назначить сочетание клавиш элементу, выполните команду...
 
Artyom Trishkin:

Has the cat stepped on the keyboard and made a trade for you?

Do it yourself - it's not hard.

I have no idea how to do it. I couldn't find a script like that.