RAD Studio |  |

The Three Char Types
See Also
Collapse All

One-character constants, such as 'A', '\t' and '007', are represented as int values. In this case, the low-order byte is sign extended into the high bit; that is, if the value is greater than 127 (base 10), the upper bit is set to -1 (=0xFF). This can be disabled by declaring that the default char type is unsigned.

The three character types, char, signed char, and unsigned char, require an 8-bit (one byte) storage. By default, the compiler treats character declarations as signed. Use the –K compiler option to treat character declarations as unsigned. The behavior of C programs is unaffected by the distinction between the three character types.

In a C++ program, a function can be overloaded with arguments of type char, signed char, or unsigned char. For example, the following function prototypes are valid and distinct:

Copy Code

    void func(char ch);
    void func(signed char ch);
    void func(unsigned char ch);

If only one of the above prototypes exists, it will accept any of the three character types. For example, the following is acceptable:

Copy Code

    void func(unsigned char ch);
    void main(void)
    {
      signed char ch = 'x';
      func(ch);
    }

See Also

Constants

Integer Constants

Integer Constant Without L Or U

Floating Point Constants

Character Constants

Escape Sequences

Wide-character And Multi-character Constants

String Constants

Enumeration Constants

Constants And Internal Representation

Internal Representation Of Numerical Types

Constant Expressions

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!