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

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); 
原文地址:https://www.cnblogs.com/lexus/p/2513160.html