The #pragma pack from the smallmicrosoft stuff is a very peculiar thing (the way it works now surprises me, to be honest). Not surprisingly, the standard alignas works differently.
Here's more:
#include <iostream>
struct A
{
short j;
} __attribute__((aligned(4)));
int main()
{
A q[2];
std::cout << sizeof(q) << std::endl; // 8return0;
}
The #pragma pack of the small softwares is a very peculiar thing (the way it works is surprising to me now, to be honest). No wonder that alignas works differently in the standard.
come on )
#include <iostream>
struct A
{
short j;
} alignas(4) ;
int main()
{
A q[2];
std::cout << sizeof(q) << std::endl; // 4return0;
}
#pragma pack works fine on gcc as well, and what you wrote is just an internal gcc attribute that works differently than aligned.
#pragma pack works fine on gcc as well, and what you've written is just an internal gcc attribute that works differently than aligned.
So what does this example show? That you haven't figured out the use of alignas? Even the compiler swears at the code:
1.cc:7:3: warning: attribute ignored in declaration of 'struct A' [-Wattributes]
7 | } alignas(4) ;
| ^~~~~~~
1.cc:7:3: note: attribute for 'struct A' must follow the 'struct' keyword
The #pragma pack is an odd little softie creation that gcc only supports for compatibility.
TheXpert: And note that this is default behavior, not for smallmicrosoft compatibility
I don't get the idea. Everything is fine in the example, I don't see a problem. Default - structure alignment == take the strictest requirement-alignment among members.
struct {char;} == 1, struct {char;short} == 2, struct {char;int} == 4, etc. It's like that everywhere. And long long == eight, so alignas has no effect.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
So what's the bug?
You declare an array of two elements with two bytes each and get 4 bytes as it should be. Where is the bug? What is it?
It's this.
You align it to 4 and 2 elements will occupy 2*8 bytes.
Sorry, but if you write that, you don't understand the subject.
Analogous to the crosses:
The mistake probably isn't here?
I'm sorry, but if you write that, you don't understand the subject.
No, you don't seem to understand.
No, you don't seem to understand.
The #pragma pack from the smallmicrosoft stuff is a very peculiar thing (the way it works now surprises me, to be honest). Not surprisingly, the standard alignas works differently.
Here's more:
The #pragma pack of the small softwares is a very peculiar thing (the way it works is surprising to me now, to be honest). No wonder that alignas works differently in the standard.
come on )
#pragma pack works fine on gcc as well, and what you wrote is just an internal gcc attribute that works differently than aligned.
Come on, already.)
#pragma pack works fine on gcc as well, and what you've written is just an internal gcc attribute that works differently than aligned.
So what does this example show? That you haven't figured out the use of alignas? Even the compiler swears at the code:
The #pragma pack is an odd little softie creation that gcc only supports for compatibility.
So what does this example show? That you haven't figured out how to use alignas?
I agree, I messed up.
Here's the right code.
so alignas is not analogous to packaging.
because in the same gcc (so that without smallsoft) the default multiple of packing is 8
because:
but with alignas(8)
And note that this is default behavior, not for smallmicrosoft compatibility
I don't get the idea. Everything is fine in the example, I don't see a problem. Default - structure alignment == take the strictest requirement-alignment among members.
struct {char;} == 1, struct {char;short} == 2, struct {char;int} == 4, etc. It's like that everywhere. And long long == eight, so alignas has no effect.
I don't get the idea. Everything is fine in the example, I don't see the problem.
Yes, you're right, the example is no indicator.
The bottom line is that mql pack works as #pragma pack and not alignas.