有人可以帮我处理浮点变量的字节顺序吗?实际上,代码在 Solaris 上可以正常工作,但在 Windows Xp 上却不行。这是我的代码的一个示例: ....
int x_snd=1;
float y_snd=1.13;
struct {
int xx_snd;
float yy_snd;
} data_snd;
int x_rec;
float y_rec;
struct {
int xx_rec;
float yy_rec;
} data_rec;
//marshalling
data_snd.xx_snd=htons(x_snd);
data_snd.yy_snd=htonl(*(int*) &y_snd);
//write data to socket
send(sock1, &data_snd, ...
//clean ...
//read data from socket
if recv(sock, &data_rec ...
//unmarshalling
x_rec=ntohs(data_rec.xx_rec);
y_rec= *(float*) &(ntohl(data_rec.yy_rec));
...
代码在 Unix 上用 gcc 编译,在 wndows 上用 MSVC++6 编译。您的任何帮助将不胜感激,如果您能指导我访问任何提供有关字节序的有用信息的链接或文档,我将很高兴...
提前感谢您的帮助,mk