|
3驿站币
美国同学发来的题,我翻译了一下。应该就是按翻译上说的,给出了函数的格式,实现把int值存储到指向由int指向的位置的4个字节位置。
int is_little_endian(void (*store)(int*,int)) {
int x;
// The cast below is to have an unsigned char pointer pointing
// to the first byte of int variable x. You can use it
// in your code to observe x one byte at a time.
unsigned char *byte_ptr = (unsigned char*)(&x);
// This is how you call store function.
// After the function call, value 1 is stored
// in the four bytes x is referring to in some order.
// One of the four bytes will have the value 1, and the
// other three bytes will have the value 0.
// You can call store function with any value that you think
// will help you solve the problem.
// Refer to code in Figure 2.4 on page 45 of the textbook
// to see how you retrieve one byte at a time.
store(&x, 1);
// Replace 0 with a proper value that will be 0 when store
// is not little endian and 1 when store is little endian.
return 0;
}
@Syc |
-
1
-
2
最佳答案
查看完整内容
这个问题就是用他描述的文本意思来实现检测当前是大端还是小端的问题吧?
看看这篇文章,马上就能解决楼主的问题了:
判断计算机是大端还是小端
https://blog.csdn.net/lwfcgz/article/details/50476051
上一篇: 窗口跟随显示问题下一篇: 利用post去自动登录并发起请求
|