Errors, bugs, questions - page 2498

 
Andrei Trukhanovich:

In that case, imho, it shouldn't.

Why shouldn't the size here be a multiple of four?

It turns out that classes can be aligned too.

 
fxsaber:

Why shouldn't the size here be a multiple of four?

It turns out that classes can be aligned too.

because this is an internal alignment. The next external variable will most likely be placed with an alignment of 8 regardless ofthe size of the structure.

 
Andrei Trukhanovich:

because it is an internal alignment

Then I'm afraid the point of alignment is lost

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

void OnStart()
{
  Print(sizeof(A)); // 2
  
  const int handle = FileOpen(__FILE__, FILE_WRITE | FILE_BIN);
  
  if (handle != INVALID_HANDLE)
  {
    A a = {0};
    
    FileWriteStruct(handle, a);
    Print(FileTell(handle)); // 2
    
    FileClose(handle);
  }
}
 
fxsaber:

Then I'm afraid the point of alignment is lost

the point of alignment is to make the internal variable addresses a multiple of the alignment.

 
Andrei Trukhanovich:

the point of alignment is to make the internal variable addresses a multiple of the alignment.

I tried to compare your statement with the Documentation, but I still do not understand.

 
Andrei Trukhanovich:

An unsawned thing, apparently. There's clearly already a mistake here:

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

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

I tried to compare your statement with Documentation, but I don't understand.

I think the help hasn't been updated, i.e. in the build with C# support (in winter?) there was a description of how the alignment now works.

i just googled an article on hobber about alignment. i think it will work the same way in MT5 nowhttps://habr.com/ru/post/142662/

 
Igor Makanu:

I think the help has not been updated, it seems that in the build with C# support (in winter?) there was a description of how alignment works now

I googled this article on hobber about alignment. It seems the same thing will work in MT5 nowhttps://habr.com/ru/post/142662/

I read the article and comments to it. I don't understand the alignment algorithm at all. It is set to pack(4) but for some reason something aligns to 2 and something aligns to 4.

 
fxsaber:

I ran the article and the comments on it. I don't understand the alignment algorithm at all. It's pack(4), but for some reason something aligns to 2, something to 4.

Why bother? The default single alignment is the same as before (and is unlikely to change), the pack specifier is crooked. If you really need it, you can insert the add-on yourself.

 
Vict:

Why bother? The default single alignment is the same as before (and unlikely to change), the pack specifier is crooked. If you really need it, you can insert an add-on yourself.

I want to get to the bottom of it.

Reason: