考虑下面的代码:字节序变通所需
#include "stdio.h"
typedef struct CustomStruct
{
short Element1[10];
}CustomStruct;
void F2(char* Y)
{
*Y=0x00;
Y++;
*Y=0x1F;
}
void F1(CustomStruct* X)
{
F2((char *)X);
printf("s = %x\n", (*X).Element1[0]);
}
int main(void)
{
CustomStruct s;
F1(&s);
return 0;
}
在运行时,通过调用函数F1
末,我通过使用不同的编译器得到不同的结果。
(*X).Element1[0] = 0x1f00
在一些编译器和(*X).Element1[0] = 0x001f
与另一个。
我很清楚这是一个排序问题。
是否有任何编译器选项或解决方案使用,以便我得到(*X).Element1[0] = 0x001f
而不管使用的编译器?
向我们展示你如何填充'部件1 ' –
对不起,我没有明白你的意思。你的意思是说你需要F2的实际身体吗?我认为它没用,因为我保证在F2的末尾你有Y [0] = 0x00和Y [1] = 0x1F。 –
您正试图提供该保证。我们试图告诉你如何,但除非你给我们提供真正的代码来工作,否则我们只能猜测你在做什么。 –