浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

c - printf of a size_t variable with lld, ld and d type identifiers - Stack Overflow

Your code aptly demonstrates Undefined Behavior. Note that in case of variadic arguments no type checking is done for parameters. This is when an explicit cast becomes necessary. In fact the following should therefore be used:

 printf("lld=%lld, ld=%ld, u=%u\n", 
         (unsigned long long)temp, 
         (unsigned long)temp, 
         (unsigned int)temp);

As an aside remember the specifier for size_t is z. So:

 printf("zd=%zd\n", temp); 
posted on 2012-05-22 13:03  lexus  阅读(299)  评论(0)    收藏  举报