Wednesday, November 15, 2006

Integer Types In C and C++

Unless I am switching back and forth between compilers often, I tend to need a kick (or look up) to recall the different implementations of integer types.

The below page of Jack Klein's is just that kick.

Integer Types In C and C++


The introduction, a copy-paste from the above site, and the sample program to run through your compiler is below.

Introduction

You would think that the basic integer types provided by the C and C++ languages wouldn't cause an much confusion as they do. Almost every day there are posts in the C and C++ newsgroups which show that many newcomers do not understand them. Some experienced programmers who are only familiar with one platform do not understand them either.

The most common source of confusion are the sizes of the integer types, and the range of values which they can hold. That is because the languages leave many features of the integer types implementation-defined, meaning that it is up to the particular compiler to determine their exact specifications. C and C++ do set minimum requirements for each of the integer types, but the compiler is free to exceed these limits.

Each compiler is required to document its implementation. This information should be available in the printed manuals, online help, or man pages which come with the compiler.

In addition, there is a required standard header named <limits.h> (&ltclimits> in newer C++ compilers) that provides information about the integer types that can be used in your programs at run time. A compiler is not required to provide a header like <limits.h> as a readable text file, but I do not know of any compilers which do not.

There are programs on this page to display the information that this file contains.



A Program To Display Integer Type Information Standard C++ Compilers


#include <iostream>
#include <climits>

using std::cout;
using std::endl;

volatile int char_min = CHAR_MIN;

int main(void)
{
cout << "Size of boolean type is "
<< sizeof(bool) << " byte(s)"
<< "\n\n";

cout << "Number of bits in a character: "
<< CHAR_BIT << '\n';
cout << "Size of character types is "
<
<< " byte" << '\n';
cout << "Signed char min: "
<< SCHAR_MIN << " max: "
<<< '\n';
cout << "Unsigned char min: 0 max: "
<< UCHAR_MAX << '\n';

cout << "Default char is ";

if (char_min < 0)
cout << "signed";
else if (char_min == 0)
cout << "unsigned";
else
cout << "non-standard";
cout << "\n\n";

cout << "Size of short int types is "
<< sizeof(short) << " bytes"
<< '\n';
cout << "Signed short min: "
<< SHRT_MIN << " max: "
<< SHRT_MAX << '\n';
cout << "Unsigned short min: 0 max: "
<< USHRT_MAX << "\n\n";

cout << "Size of int types is "
<< sizeof(int) << " bytes"
<< '\n';
cout << "Signed int min: "
<< INT_MIN << " max: "
<< INT_MAX << '\n';
cout << "Unsigned int min: 0 max: "
<< UINT_MAX << "\n\n";

cout << "Size of long int types is "
<< sizeof(long) << " bytes"
<< '\n';
cout << "Signed long min: " <<
LONG_MIN << " max: "
<< LONG_MAX << '\n';
cout << "Unsigned long min: 0 max: "
<< ULONG_MAX << endl;

return 0;
}

Keywords: C++, types, integer, int, short, long, char, bool, sizeof, C, compiler implementation of integer types, unsigned.

2 comments:

ed said...

一夜情聊天室,一夜情,情色聊天室,情色,美女交友,交友,AIO交友愛情館,AIO,成人交友,愛情公寓,做愛影片,做愛,性愛,微風成人區,微風成人,嘟嘟成人網,成人影片,成人,成人貼圖,18成人,成人圖片區,成人圖片,成人影城,成人小說,成人文章,成人網站,成人論壇,情色貼圖,色情貼圖,色情A片,A片,色情小說,情色小說,情色文學,寄情築園小遊戲, 情色A片,色情影片,AV女優,AV,A漫,免費A片,A片下載

情色,A片,AIO,AV,日本AV,色情A片,AV女優,A漫,免費A片,A片下載,情色A片,哈啦聊天室,UT聊天室,聊天室,豆豆聊天室,色情聊天室,尋夢園聊天室,080視訊聊天室,080聊天室,080苗栗人聊天室,免費視訊聊天,上班族聊天室,080中部人聊天室,視訊聊天室,視訊聊天,成人聊天室,一夜情聊天室,辣妹視訊,情色視訊,成人,成人影片,成人光碟,成人影城,自拍

A片,AIO,AV,日本AV,色情A片,AV女優,A漫,AIO交友愛情館,線上A片,免費A片,A片下載,情色A片,微風成人,嘟嘟成人網,成人,成人影片,成人光碟,成人影城,成人交友,愛情公寓,色情聊天室,情色貼圖,色情,色情影片,做愛,情色,哈啦聊天室,聊天室,UT聊天室,豆豆聊天室,尋夢園聊天室,080視訊聊天室,080聊天室,080苗栗人聊天室,自拍,性愛

情趣用品,情趣用品,情趣,情趣,A片,A片,情色,A片,A片,情色,情趣用品,情趣用品,A片,A片,情色,情色

情色視訊,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,視訊交友90739,視訊,免費視訊,情人視訊網,視訊辣妹,影音視訊聊天室,視訊交友,視訊聊天,免費視訊聊天室,成人視訊,UT聊天室,聊天室,豆豆聊天室,色情聊天室,尋夢園聊天室,聊天室尋夢園,080聊天室,080苗栗人聊天室,上班族聊天室,小高聊天室

6K聊天室,080中部人聊天室,聊天室交友,成人聊天室,中部人聊天室,情色聊天室,AV女優,AV,A片,情人薇珍妮,愛情公寓,情色,情色貼圖,情色文學,色情小說,色情,寄情築園小遊戲,AIO交友愛情館,情色電影,一葉情貼圖片區,色情遊戲

言情小說,情色論壇,色情網站,微風成人,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人網站,免費影片,色情影片,自拍,hilive,做愛,微風成人,微風論壇,AIO

Levitra kaufen said...

I am wondering what the asian wanted to say about the text. would be interesting to know.