源代码:
(操作系统作业)printf("\nMemory attached at %X\n",(int)shm);
shm是个char*地址;
gcc编译出现警告:lcy@lcy-Lenovo-R720-15IKBN:~ $ gcc -o shmread shmread.c
shmread.c: In function ‘main’:
shmread.c:31:40: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
printf("\nMemory attached at %X\n",(int)shm);
^
错误原因:企图将指针类型转换为无符号32位整型数,但这在64位环境下会发生兼容性问题。
解决办法:printf("\nMemory attached at %ld\n",(long)shm);
参考资料:
16位编译器
32位编译器
64位编译器