PS-Trainer C - Entwicklung
Variable: Typen
Homepage von PS-Trainer - C-Entwicklung - Variable - an PS-Trainer
PS-Trainer PS-Trainer

Variables Storage classes, types, structures, pointers, arrays
Fundamental types Fundamental types
Data type constants Ranges of values for integral data types
int (short, long) Integer type (family) specifier (whole numbers)
signed and unsigned Signed and unsigned modifiers can be used with any integral type.
char (escape sequences) Type used to store the value of a character set member, or to store a single byte of data.
float (double) (float constants) Float type (family) specifier (fractional numbers)
void Describes an empty set of values.


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.

Category Type Contents Size

Integral
char Type char is an integral type that usually contains members of the execution character set (e.g. 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.
1 byte
  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.
2 bytes

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.
4 bytes

__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. 1,2,4, or 8 bytes

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.
4 bytes

Floating
float Type float is the smallest floating type. 4 bytes

double Type double is a floating type that is larger than or equal to type float, but shorter than or equal to the size of type long double. 8 bytes
  long double Type long double is a floating type that is equal to type double. 8 bytes

Data Type Constants
Data type constants are implementation-dependent ranges of values allowed for integral data types.

Character & integer types
Float & double types

The constants listed below give the ranges for the integral data types and are defined in LIMITS.H.
Note: The /J compiler option changes the default char type to unsigned.

Constant Value Meaning
SCHAR_MAX
127 Maximum signed char value
SCHAR_MIN
-128 Minimum signed char value
UCHAR_MAX
255 (0xFF) Maximum unsigned char value
CHAR_BIT
8 Number of bits in a char
USHRT_MAX
65535 (0xFFFF) Maximum unsigned short value
SHRT_MAX
32767 Maximum (signed) short value
SHRT_MIN
-32768 Minimum (signed) short value
UINT_MAX
4294967295 (0xFFFFFFFF) Maximum unsigned int value
ULONG_MAX
4294967295 (0xFFFFFFFF) Maximum unsigned long value
INT_MAX
2147483647 Maximum (signed) int value
INT_MIN
-2147483647–1 Minimum (signed) int value
LONG_MAX
2147483647 Maximum (signed) long value
LONG_MIN
-2147483647–1 Minimum (signed) long value
CHAR_MAX
127 (255 if /J option used) Maximum char value
CHAR_MIN
-128 (0 if /J option used) Minimum char value
MB_LEN_MAX 2 Maximum number of bytes in multibyte char
Example:
Click this link to open the source code of an <integer family type test program>

The following constants give the range and other characteristics of the double and float data types, and are defined in FLOAT.H:

Constant Value Description
DBL_DIG
15 # of decimal digits of precision
DBL_EPSILON
2.2204460492503131E-016 Smallest such that 1.0+DBL_EPSILON !=1.0
DBL_MANT_DIG
53 # of bits in mantissa
DBL_MAX 1.7976931348623158E+308 Maximum value
DBL_MAX_10_EXP 308 Maximum decimal exponent
DBL_MAX_EXP 1024 Maximum binary exponent
DBL_MIN 2.2250738585072014E-308 Minimum positive value
DBL_MIN_10_EXP
(-307) Minimum decimal exponent
DBL_MIN_EXP
(-1021) Minimum binary exponent
_DBL_RADIX 2
Exponent radix
_DBL_ROUNDS 1
Addition rounding: near
FLT_DIG
6 Number of decimal digits of precision
FLT_EPSILON 1.192092896E-07F Smallest such that 1.0+FLT_EPSILON !=1.0
FLT_MANT_DIG 24 Number of bits in mantissa
FLT_MAX 3.402823466E+38F Maximum value
FLT_MAX_10_EXP 38 Maximum decimal exponent
FLT_MAX_EXP 128 Maximum binary exponent
FLT_MIN 1.175494351E-38F Minimum positive value
FLT_MIN_10_EXP (-37) Minimum decimal exponent
FLT_MIN_EXP (-150;125) Minimum binary exponent
FLT_RADIX 2 Exponent radix
FLT_ROUNDS 1 Addition rounding: near

int
[type-specifier] [ signed | unsigned ] integer-modifier [ int ] declarator-list;

type-specifier
Specifies a base_type, struct, union, enum type, or type identifier.
An optional storage specification can precede type-specifier.

integer-modifier
Specifies the keyword small, short, long, or hyper, which selects the size of the integer data.
On 16-bit platforms, the size qualifier must be present.

declarator-list
Specifies one or more standard C declarators, such as identifiers, pointer declarators, and array declarators. (Function declarators and bit-field declarations are not allowed in structures that are transmitted in remote procedure calls. These declarators are allowed in structures that are not transmitted.) Separate multiple declarators with commas.

Remarks
Size and range of values:
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.
On 32-bit platforms, the keyword int specifies a 32-bit signed integer. On 16-bit platforms, the keyword int is an optional keyword that can accompany the keywords small, short, and long.
Type Name
Bytes Other Names Range of Values
int

*
signed,
signed int

System dependent
unsigned int
* unsigned System dependent
__int8
1 char,
signed char
–128 to 127
__int16
2 short,
short int,
signed short int
–32,768 to 32,767
__int32
4 signed,
signed int
–2,147,483,648 to 2,147,483,647
__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,
signed short int
–32,768 to 32,767
unsigned short
2 unsigned short int 0 to 65,535
long
4 long int,
signed long int
–2,147,483,648 to 2,147,483,647
unsigned long
4 unsigned long int 0 to 4,294,967,295
enum * none Same as int

Integer types are among the base types of the interface definition language (IDL). They can appear as type specifiers in typedef declarations, general declarations, and function declarators (as a function-return-type specifier and as a parameter-type specifier). For the context in which type specifiers appear, see IDL.

If no integer sign specification is provided, the integer type defaults to signed.
DCE IDL compilers do not allow the keyword signed to specify the sign of integer types. Therefore, this feature is not available when you use the MIDL compiler /osf switch.

Keywords: base_types, long, /osf, short, small
Example:
Click this link to open the source code or the console (DOS) exe-program of an <integer family type test program>, both provided in ZIP-type archives. This program allows to print all current (integral) data type constants, and to test length and bit pattern of the various integral data types.
Examples:
signed short int i = 0;
int j = i;
typedef struct {
small int i1;
short i2;
unsigned long int i3;
} INTSIZETYPE;

HRESULT MyFunc([in] long int lCount);
Examples of integer-type values and their internal representation:
In any system of numbers, a value is represented by a series x0*base^0 + x1*base^1 + x2*base^2... in reverse annotation:
Decimal example: 1234 = 1*10^3 + 2*10^2 + 3*10^1 + 4*10^0 = 1*1000 + 2*100 + 3*10 + 4*1 = 1000 + 200 + 30 + 4 = 1234
Hex example: hex1A2B = 1*16^3 + 10*16^2 + 2*16^1 + 11*16^0 = 1*4096 + 10*256 + 2*16 + 11*1 = 4096 + 2560 + 32 + 11 = 6699
Oct example: oct1234 = 1*8^3 + 2*8^2 + 3*8^1 + 4*8^0 = 1*512 + 2*64 + 3*8 + 4*1 = 512 + 128 + 24 + 4 = 668
Bin example: bin 1010 = 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 = 1*8 + 0*4 + 1*2 + 0*1 = 8 + 0 + 2 + 0 = 10

Decimal exponents: 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000...
Hex exponents: 1, 16, 256, 4096, 65536, 1048576, 16777216, 268435456, ...
Bin exponents: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, ...
Data Hex Binary
unsigned short (0) 0000 0000 0000 0000 0000
unsigned short (1) 0001 0000 0000 0000 0001
unsigned short (2) 0002 0000 0000 0000 0010
unsigned short (3) 0003 0000 0000 0000 0011
unsigned short (15) 000F 0000 0000 0000 1111
unsigned short (16) 0010 0000 0000 0001 0000
unsigned short (32767) 7FFF 0111 1111 1111 1111
unsigned short (32768) 8000 1000 0000 0000 0000
unsigned short (65535) FFFF 1111 1111 1111 1111
short (1) 0001 0000 0000 0000 0001
short (16) 0010 0000 0000 0001 0000
short (32767) 7FFF 0111 1111 1111 1111
short (-1) FFFF 1111 1111 1111 1111
short (-2) FFFE 1111 1111 1111 1110
short (-32767) 8001 1000 0000 0000 0001
int (1) 0000 0001 0000 0000 0000 0000 0000 0000 0000 0001
int (1234567890) 4996 02D2 0100 1001 1001 0110 0000 0010 1101 0010
int (-1234567890) B669 FD2E 1011 0110 0110 1001 1111 1101 0010 1110
To encode a negative number, values are stored in 2´s complement: The binary value is "binary inverted", making a 0 of every 1 and a 1 of every 0, afterwards, 1 is added.
The leftmost "hi-end" bit must be 0 in every positive number and zero. This "sign bit" is 1 in every negative number. Watch how any positive number is "inverted" to form a negative number of the same absolute value.
Unsigned types do not interpret the sign bit, their value range is positive only, but twice the absolute value of signed type of the same length.

signed and unsigned
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.

char
The char type is used to store the integer value of a member of the representable character set.
Click this Link to a table of common character sets.
That integer value is the ASCII code corresponding to the specified character.
Microsoft Specific
Character values of type unsigned char have a range from 0 to 0xFF hexadecimal. A signed char has range 0x80 to 0x7F. These ranges translate to 0 to 255 decimal, and –128 to +127 decimal, respectively. The /J compiler option changes the default from signed to unsigned.
END Microsoft Specific
The keyword char identifies a data item that has 8 bits.
To the MIDL compiler, a char is unsigned by default and is synonymous with unsigned char.
Microsoft Specific
In the Microsoft RPC compiler , the character translation tables that convert between ASCII and EBCDIC are built into the run-time libraries and cannot be changed by the user.
END Microsoft Specific
The char type is one of the base types of the interface definition language (IDL). The char type can appear as a type specifier in const declarations, typedef declarations, general declarations, and function declarators (as a function-return-type specifier and a parameter-type specifier).
DCE IDL compilers do not accept the keyword signed applied to char types. Therefore, this feature is not available when you use the MIDL compiler /osf switch.

Keywords: base_types, byte, /char, /osf, signed, string, wchar_t
Type Name
Bytes Other Names Range of Values
char
1 signed char –128 to 127
unsigned char
1 none 0 to 255
Escape Sequences
Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences.
An escape sequence is regarded as a single character and is therefore valid as a character constant.
Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark (").

The following table lists the ANSI escape sequences and what they represent.
Note that the question mark preceded by a backslash (\?) specifies a literal question mark in cases where the character sequence would be misinterpreted as a trigraph.
Escape Sequence
Represents
\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhhh ASCII character in hexadecimal notation
Microsoft Specific
If a backslash precedes a character that does not appear in this table, the compiler handles the undefined character as the character itself. For example, \x is treated as an x.
END Microsoft Specific

Escape sequences allow you to send nongraphic control characters to a display device. For example, the ESC character (\033) is often used as the first character of a control command for a terminal or printer. Some escape sequences are device-specific. For instance, the vertical-tab and formfeed escape sequences (\v and \f) do not affect screen output, but they do perform appropriate printer operations.

You can also use the backslash (\) as a continuation character. When a newline character (equivalent to pressing the RETURN key) immediately follows the backslash, the compiler ignores the backslash and the newline character and treats the next line as part of the previous line. This is useful primarily for preprocessor definitions longer than a single line.
Example:
#define assert(exp) \
( (exp) ? (void) 0:_assert( #exp, __FILE__, __LINE__ ) )
Examples of character-type values and their internal representation:
Remark: The characters 0...127 are the same in common character sets, whereas caracters 127...255 are interpreted differently, depending on the character set.
Remark: Mind that upper case characters and the corresponding lower case characters are different in 1 bit only.
hex bin unsigned char char ASCII ANSI
30 0011 0000 48 48 0 0
31 0011 0001 49 49 1 1
39 0011 1001 57 57 9 9
41 0100 0001 65 65 A A
42 0100 0010 66 66 B B
5A 0101 1010 90 90 Z Z
61 0110 0001 97 97 a a
62 0110 0010 98 98 b b
7A 0111 1010 122 122 z z
84 1000 0100 132 -124   ä
94 1001 0100 148 -108   ö
81 1001 0001 129 -127   ü
E4 1110 0100 228 -28 ä  
F6 1111 0110 246 -10 ö  
FC 1111 1100 252 -4 ü  

float
Floating types are capable of specifying values that may have fractional parts.

Floating-point numbers use the IEEE (Institute of Electrical and Electronics Engineers) format.
Single-precision values with float type have 4 bytes, consisting of a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa.
The mantissa represents a number between 1.0 and 2.0. Since the high-order bit of the mantissa is always 1, it is not stored in the number. This representation gives a range of approximately 3.4E–38 to 3.4E+38 for type float.
You can declare variables as float or double, depending on the needs of your application. The principal differences between the two types are the significance they can represent, the storage they require, and their range.

Type Name
Bytes Other Names Range of Values
float
4 none 3.4E +/- 38 (7 digits)
6-7 significant digits
double 8 none 1.7E +/- 308 (15 digits)
15-16 significant 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.
Internal representation:
Floating-point variables are represented by a mantissa, which contains the value of the number, and an exponent, which contains the order of magnitude of the number.
The right-side table shows the number of bits allocated to the mantissa and the exponent for each floating-point type. The most significant bit of any float or double is always the sign bit. If it is 1, the number is considered negative; otherwise, it is considered a positive number.
Type
Exponent length
Mantissa length
float 8 bits 23 bits
double 11 bits 52 bits
Exponents are stored in an unsigned form. Therefore the exponent is biased by half its possible value.
For type float, the bias is 127; for type double, it is 1023.
You can compute the actual exponent value by subtracting the bias value from the exponent value.

The mantissa is stored as a binary fraction greater than or equal to 1 and less than 2.
For types float and double, there is an implied leading 1 in the mantissa in the most-significant bit position, so the mantissas are actually 24 and 53 bits long, respectively, even though the most-significant bit is never stored in memory.

Instead of the storage method just described, the floating-point package can store binary floating-point numbers as denormalized numbers. "Denormalized numbers" are nonzero floating-point numbers with reserved exponent values in which the most-significant bit of the mantissa is 0.
By using the denormalized format, the range of a floating-point number can be extended at the cost of precision.
You cannot control whether a floating-point number is represented in normalized or denormalized form; the floating-point package determines the representation. The floating-point package never uses a denormalized form unless the exponent becomes less than the minimum that can be represented in a normalized form.
The right-side table shows the minimum and maximum values you can store in variables of each floating-point type.
The values listed in this table apply only to normalized floating-point numbers; denormalized floating-point numbers have a smaller minimum value.

Note that numbers retained in 80x87 registers are always represented in 80-bit normalized form; numbers can only be represented in denormalized form when stored in 32-bit or 64-bit floating-point variables (variables of type float and type long).
Type
Minimum value Maximum value
float 1.175494351 E – 38 3.402823466 E + 38
double 2.2250738585072014 E – 308 1.7976931348623158 E + 308
If precision is less of a concern than storage, consider using type float for floating-point variables.
Conversely, if precision is the most important criterion, use type double.

Floating-point variables can be promoted to a type of greater significance (from type float to type double). Promotion often occurs when you perform arithmetic on floating-point variables. This arithmetic is always done in as high a degree of precision as the variable with the highest degree of precision.
For example, consider the following type declarations:
float f_short;
double f_long;
long double f_longer;
f_short = f_short * f_long;

In the preceding example, the variable f_short is promoted to type double and multiplied by f_long; then the result is rounded to type float before being assigned to f_short.

In the following example (which uses the declarations from the preceding example), the arithmetic is done in float (32-bit) precision on the variables; the result is then promoted to type double:
f_longer = f_short * f_short;
Floating-Point Constants
A "floating-point constant" is a decimal number that represents a signed real number.
The representation of a signed real number includes an integer portion, a fractional portion, and an exponent.
Use floating-point constants to represent floating-point values that cannot be changed.

Syntax

floating-point-constant :
fractional-constant exponent-part opt floating-suffix opt
digit-sequence exponent-part floating-suffix opt


fractional-constant :
digit-sequence opt . digit-sequence
digit-sequence .


exponent-part :
e sign opt digit-sequence
E sign opt digit-sequence


sign : one of
+ –

digit-sequence :
digit
digit-sequence digit


floating-suffix : one of
f l F L

You can omit either the digits before the decimal point (the integer portion of the value) or the digits after the decimal point (the fractional portion), but not both. You can leave out the decimal point only if you include an exponent. No white-space characters can separate the digits or characters of the constant.

The following examples illustrate some forms of floating-point constants and expressions:
15.75
1.575E1 /* = 15.75 */
1575e-2/* = 15.75 */
-2.5e-3/* = -0.0025 */
25E-4/* = 0.0025 */


Floating-point constants are positive unless they are preceded by a minus sign (–). In this case, the minus sign is treated as a unary arithmetic negation operator. Floating-point constants have type float, double, long, or long double.

A floating-point constant without an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long double.
For example:
100L/* Has type long double */
100F/* Has type float */
100D/* Has type double */

The Microsoft C compiler maps long double to type double.

You can omit the integer portion of the floating-point constant, as shown in the following examples.
The number .75 can be expressed in many ways, including the following:
.0075e2
0.075e1
.075e1
75e-2
Examples of floating-point values and their internal representation:
Each number can be represented using exponent and mantissa:
Decimal: 2 = 10^0.3010320 = 10^1.30103200 = 10^2.301032000 = 10^3.30103 ......
Binary: 2 = 2^ 1.03 = 2^1.5854 = 2^2.016 = 2^4.0 20 = 2^4.322128 = 2^7.0200 = 2^7.644256 = 2^8.0
In float types both exponent and mantissa are stored separately: The exponent langth defines the number range, the mantissa length defines the precision ("significant digits").
The mantissa can be negative, this information is stored in a single "sign bit". Since the mantissa (normalized to 1.00...2.00) always starts with a 1-bit, this bit is omitted and not stored (hidden bit). To interpret a float number, this "most significant bit" has to be added.
Exponents are stored in an unsigned form + bias 127 (\x7F = bin 0111 1111). To interpret the exponent, 127 must be added.
To learn more about the internal data format of real numbers, IEEE 754, 2 tools are provided:

IEEE-754 tools:
Float_IEEE754.XLS is an Excel simulation program: decoding and encoding a real number is explained in detail.
The formulas are free to check or to copy, although they cannot be changed.
Right-click Float_IEEE754.XLS and "save target" to your disk to use it.
IEEE754.EXE is a DOS (console) program to test IEEE-754 codes in practise: no assumptions are made about the algorithm, real variables are investigated in real time: you may decode real numbers (float or double) to hex or binary, or you may encode hex strings to check the real numbers they are encoded to.
Both the EXE-program and the (free) C++ source files are included in the ZIP-type archive IEEE754.ZIP.
Right-click IEEE754.ZIP and "save target" to your disk to use it.

void
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.
The left operand of the comma operator.
The second or third operand of the conditional operator (? :).

Homepage von PS-Trainer - C-Entwicklung - Variable - an PS-Trainer

Aktuelle Daten dieser Seite Letzte Änderung:
  Geocities

 

 

 

Hosted by www.Geocities.ws

1