1. Using printf should be said to be type insecure. Therefore, the stream input and output of C ++ is introduced.
For example:
# Include "stdint. H"
# Include "iostream"
Using namespace STD;
Int main ()
{
Int64_t A = 1;
Int B = 2;
Uint32_t uin = 1;
printf (" % P \ n ", & A, & B);
printf (" % LlU \ n ", uin);
cout
Printf ("% d \ n", a, B );
Return 0;
}
The output is:
0xbfd831e0 0xbfd831dc
13823853877176303617 // Error
1 2
1 0 // Error
As you can see,Uint32_tType. When LLD is used, an error occurs,Because printf reads data from the starting address offset byte Based on the type.
Using the stream in C ++ will not cause this problem. Attention should be paid to cross-platform applications.
2. type and number of bytes [3]
% Ld: Long int, 32-bit Platform 4 bytes
% LLD: long int, 32-bit platform 8 bytes
% Lf: double
**************
Typedef signed Char int8_t
Typedef short int int16_t;
Typedef int int32_t;
# If _ wordsize = 64
Typedef long int int64_t;
# Else
_ Extension __
Typedef long int int64_t;
# Endif
Refer:
[1]Http://www.vimer.cn/2011/08/printf-%E5%B0%8F%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%A4%A7%E9%97% AE %E9%A2%98.html
[2]Http://www.cppblog.com/Solstice/archive/2010/04/06/111788.aspx
[3] type and number of bytes
Http://blog.sina.com.cn/s/blog_4b9eab320100sdex.html
[4] exploration of printf implementation
Http://www.cnblogs.com/hnrainll/archive/2011/08/05/2128496.html