以下代码在大小端机器上运行会有差异吗?
#include<stdio.h>
#include <stdlib.h>
#pragma (1)
typedef struct {
unsigned char a1 : 1;
unsigned char a2 : 1;
unsigned char a3 : 1;
unsigned char a4 : 1;
unsigned char a5 : 1;
unsigned char a6 : 3;
}Bbit;
const char* str[] = {
"aaa",
"bbb",
"ccc",
"ddd",
"eee"
};
int main()
{
Bbit bit;
bit.a1 = 1;
bit.a2 = 1;
bit.a3 = 1;
bit.a4 = 1;
bit.a5 = 1;
bit.a6 = 0;
unsigned char* p;
p = (unsigned char*)&bit;
for (int i = 0; i < 5; i++) {
if ((unsigned char)*p & (1 << i)) {
printf("str = %s\n", str[i]);
}
}
system("pause");
return 0;
}