Tag: A sign Eric indicates the value with document Oat Sentinel
Each C + + implementation identifies properties of built-in types in <limits>, <climits>, <limits.h>, and <float.h>, so programmers can use these properties to check for numerical limits, Set Sentinel mechanism and so on. They are very important for developing the underlying program. If you feel the need for these attribute values, it is likely that your work is closer to the hardware. But there are other uses for these properties, for example, it's normal to be curious about the language implementation details: "How big is an int?" "," Char is signed? And so on It is difficult to find the correct answers to these questions from the system documentation, and the C + + standard does not specifically define these issues. A better approach is to write a short applet to get answers to these questions:
#include <limits>
cout<< "number of bytes in an int:" <<sizeof (int) << ' \ n ';cout<< "largest int:" <<int_max << ' \ n ';cout<< "smallest int value:" <<numeric_limits<int>::min () << ' \ n '; if (numeric_ limits<char>::is_signed) cout<< "Char is signed\n", Else cout<< "char is unsigned\n"; Char Ch=numeric_ Limits<char>::min ();cout<< "The char with the smallest positive value:" <<ch<< ' \ n ';cout< < "The int value of the char with the smallest positive value:" <<int (ch) << ' \ n ';
If you are writing a program that will be used on a variety of hardware platforms, it is valuable to get the information in the program. Another approach is to hard code this information into the program, but this is disastrous for maintenance personnel.
These property values are also useful for overflow detection.
Principles and Practice of C + + programming (Advanced article)
Numerical limitations------C + + programming principles and Practices (advanced)