您的位置:首页 > 理论基础

第7周 深入理解计算机系统(第二版) 例题2.3

2016-05-12 17:21 225 查看
问题及代码:

/*打印程序对象的字节表示*/
#include<stdio.h>
typedef unsigned char *byte_pointer;
/*使用强制类型转换来规避类型系统*/
void show_bytes(byte_pointer start,int len)  //start是一个数组名
{
int i;
for(i=0;i<len;i++)
printf(".2x",start[i]);
printf("\n");
}
void show_int(int x)
{
show_bytes((byte_pointer) &x,sizeof(int));
}
void show_float(float x)
{
show_bytes((byte_pointer) &x,sizeof(float));
}
void show_pointer(vodi *x)
{
show_bytes((byte_pointer) &x,sizeof(void *));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: