try below code at - https://onlinegdb.com/H1Sf_PAiI
#include<iostream>
using namespace std;
struct Str
{
char c;
int ch1:56;
double d;
int s;
int ch:32;
}st;
int main()
{
cout<<sizeof st<<endl;
return 0;
}
output
main.cpp:7:10: warning: width of ‘Str::ch1’ exceeds its type
32
Then I reduced ch1 bit field to 32 bits. It worked..!
try below code at - https://onlinegdb.com/BkD4YP0oI
#include<iostream>
using namespace std;
struct Str
{
char c;
int ch1:32;
double d;
int s;
int ch:32;
}st;
int main()
{
cout<<sizeof st<<endl;
return 0;
}
output
24
Rule 1 and 2 in the above image are incorrect?