DOC

Fundamental Types

By Elsie Dunn,2014-07-19 19:16
9 views 0
fundamental big fundamental fundamental basic types incompatible types be fundamental to fundamental engine sys types.h for all skin types rawtypes

Fundamental Types

    Fundamental types in C++ are divided into three categories: “integral,” “floating,” and “void.” Integral types are capable of handling whole numbers. Floating types are capable of specifying values that may have fractional parts. The void type describes an empty set of values. No variable of type void can be specified it is used primarily to declare functions that return no values or to declare “generic” pointers to untyped or arbitrarily typed data. Any expression can be explicitly converted or cast to type void. However, such expressions are restricted to the following uses:

    ; An expression statement. (See Chapter 4, Expressions, for more information.)

    ; The left operand of the comma operator. (See Comma Operator in Chapter 4 for

    more information.)

    ; The second or third operand of the conditional operator (? :). (See Expressions

    with the Conditional Operator in Chapter 4 for more information.)

    Table 2.3 explains the restrictions on type sizes. These restrictions are independent of the Microsoft implementation.

    Table 2.3 Fundamental Types of the C++ Language

    Category Type Contents

    Integral char Type char is an integral type that usually contains

    members of the execution character set in Microsoft

    C++, this is ASCII.

     The C++ compiler treats variables of type char, signed

    char, and unsigned char as having different types.

    Variables of type char are promoted to int as if they

    are type signed char by default, unless the /J

    compilation option is used. In this case they are treated

    as type unsigned char and are promoted to int without

    sign extension.

     short Type short int (or simply short) is an integral type that

    is larger than or equal to the size of type char, and

    shorter than or equal to the size of type int.

     Objects of type short can be declared as signed short

    or unsigned short. Signed short is a synonym for short.

     int Type int is an integral type that is larger than or equal

    to the size of type short int, and shorter than or equal

    to the size of type long.

     Objects of type int can be declared as signed int or

    unsigned int. Signed int is a synonym for int.

     __intn Sized integer, where n is the size, in bits, of the

    integer variable. The value of n can be 8, 16, 32, or

    64.

     long Type long (or long int) is an integral type that is larger

    than or equal to the size of type int.

     Objects of type long can be declared as signed long or

    unsigned long. Signed long is a synonym for long.

    Floating float Type float is the smallest floating type.

     double Type double is a floating type that is larger than or

    equal to type float, but shorter than or equal to the 1size of type long double.

    1 long double Type long double is a floating type that is equal to type

    double.

1 The representation of long double and double is identical. However, long double

    and double are separate types.

    Microsoft Specific

    Table 2.4 lists the amount of storage required for fundamental types in Microsoft C++.

    Table 2.4 Sizes of Fundamental Types

    Type Size

    char, unsigned char, signed char 1 byte

    short, unsigned short 2 bytes

    int, unsigned int 4 bytes

    long, unsigned long 4 bytes

    float 4 bytes

    double 8 bytes

    1long double 8 bytes

1 The representation of long double and double is identical. However, long double

    and double are separate types.

    For more information about type conversion, see Chapter 3, Standard Conversions. END Microsoft Specific

Send feedback to MSDN. Look here for MSDN Online resources.

    Data Type Ranges C/C++ recognizes the types shown in the table below.

    Type Name Bytes Other Names Range of Values

    int * signed, System dependent

    signed int

    unsigned int * unsigned System dependent __int8 1 char, 128 to 127

    signed char

    __int16 2 short, 32,768 to 32,767

    short int,

    signed short int

    __int32 4 signed, 2,147,483,648 to 2,147,483,647

    signed int

    __int64 8 none 9,223,372,036,854,775,808 to

    9,223,372,036,854,775,807 char 1 signed char 128 to 127

    unsigned char 1 none 0 to 255

    short 2 short int, 32,768 to 32,767

    signed short int

    unsigned short 2 unsigned short int 0 to 65,535

    long 4 long int, 2,147,483,648 to 2,147,483,647

    signed long int

unsigned long 4 unsigned long int 0 to 4,294,967,295

    enum * none Same as int

    float 4 none 3.4E +/- 38 (7 digits)

    double 8 none 1.7E +/- 308 (15 digits)

    long double 10 none 1.2E +/- 4932 (19 digits)

    The long double data type (80-bit, 10-byte precision) is mapped directly to double (64-bit, 8- byte precision) in Windows NT and Windows 95.

    Signed and unsigned are modifiers that can be used with any integral type. The char type is signed by default, but you can specify /J to make it unsigned by default. The int and unsigned int types have the size of the system word. This is two bytes (the same as short and unsigned short) in MS-DOS and 16-bit versions of Windows, and 4 bytes in 32-bit operating systems. However, portable code should not depend on the size of int.

    Microsoft C/C++ also features support for sized integer types. See __int8, __int16,

    __int32, __int64 for more information. Also see Integer Limits.

Send feedback to MSDN. Look here for MSDN Online resources.

Report this document

For any questions or suggestions please email
cust-service@docsford.com