作为一个相当可怜的替代品。 (注意 之前的字符X是一个字母,而不是一个数字。) - 呃********* @ sun.com 如果您没有忘记包含< stdlib.h>的,则不需要返回值的演员表。如果你忘了它可能会让编译器继续标记可能是一个严重错误的内容。The cast of the return value is not needed if you didn''t forgotto include <stdlib.h>. If you forgot it may keep the compilerfrom flagging what might be a serious bug. %X格式说明符需要一个unsigned int参数。 你传给它一个指针。你有没有试过 printf(内存分配在地址%p \ n,(无效)bpp); 这是打印地址的正确格式说明符? 或者,如果你坚持使用%X,你是否至少尝试将 地址转换为unsigned int?这不是我要为便携式程序推荐的b 或者有任何保证 结果值有意义,但至少它会 确保printf()会收到一个unsigned int,其中 需要一个。The "%X" format specifier expects an unsigned int argument.You pass it a pointer instead. Did you try insteadprintf("Memory was allocated at address %p\n", (void) bpp);which is the correct format specifier for printing out addresses?Or, if you insist on "%X", did you at least try to cast theaddress to an unsigned int? Not that this is something I wouldrecommend for a portable program or that there is any guaranteethat the resulting value makes any sense, but at least it wouldmake sure that printf() would receive an unsigned int where itexpects one. 很可能unsigned int只有两个字节 在您的机器上,无论内存模型是什么。 (一个术语C 标准不使用,因此它是C的扩展)。如果对于 ,则是小内存模型。地址也有2个字节使用 %X格式说明符可能会生成看起来像某个合理地址的内容,而使用大内存模型, obvioulsy只会打印出垃圾。 printf()和其他变量/> adic函数不喜欢它,如果它们被骗 - 你传递它们的争论 - 更好地适合格式说明符。 问候,Jens - \ Jens Thoms Toerring ___ jt@toerring.de \ __________________________ http:/ /toerring.de 这篇关于奇怪的malloc行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 03:35
查看更多