Home > C++ > climits Symbolic Constants

climits Symbolic Constants

There can be situations from a code snippet needs to start from the first allowable value of variable of a particular type and goes until the final value that the type support. This kind of scenarios are frequent in embedded programming at least, which I am familiar with.

In C++ there are some symbolic constants available through which one can determine the minimum and max value of particular data type. These constants are a part of climits header files.

The following code snippet demonstrates this functionality

void showCLimitsSymbolicConstants(){
    std::cout<<"CHAR_BIT: "<<CHAR_BIT<<"\n";    //Number of bits in a char
    std::cout<<"CHAR_MIN: "<<CHAR_MIN<<"\tCHAR_MAX: "<<CHAR_MAX<<"\n";    //Min and maximum char value
    std::cout<<"SCHAR_MAX: "<<SCHAR_MAX<<"\tSCHAR_MIN: "<<SCHAR_MIN<<"\n"; //Max and Min signed char value
    std::cout<<"UCHAR_MAX: "<<UCHAR_MAX<<"\n"; //Max unsigned char value
    std::cout<<"SHRT_MAX: "<<SHRT_MAX<<"\tSHRT_MIN: "<<SHRT_MIN<<"\n";  //Max & min short value
    std::cout<<"USHRT_MAX: "<<USHRT_MAX<<"\n"; //max unsigned short value
    std::cout<<"INT_MAX: "<<INT_MAX<<"\tINT_MIN: "<<INT_MIN<<"\n"; //max and min signed int value
    std::cout<<"UINT_MAX: "<<UINT_MAX<<"\n"; //max unsigned int value
    std::cout<<"LONG_MAX: "<<LONG_MAX<<"\tLONG_MIN: "<<LONG_MIN<<"\n"; //max and min long  value
    std::cout<<"ULONG_MAX: "<<ULONG_MAX<<"\n";//max unsigned long value
    std::cout<<"LLONG_MAX: "<<LLONG_MAX<<"\tLLONG_MIN: "<<LLONG_MIN<<"\n";//max and min long long  value
    std::cout<<"ULLONG_MAX: "<<ULLONG_MAX<<"\n";//max unsigned long long value
Categories: C++ Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: