signed/unsigned char/short/int/long [was: #defines with parameters]

T. William Wells bill at twwells.uucp
Wed Nov 30 07:25:39 AEST 1988


In article <277 at aber-cs.UUCP> pcg at cs.aber.ac.uk (Piercarlo Grandi) writes:
: As I understand it, this means that char,short,int,long are distinct
: types, whereas unsigned and signed are type modifiers. In a sense then,
: the view of dpANS is that unsigned [int] and [signed] int are the same
: type, only that one has a sign and the other hasn't.

These are the C int-ish types

the types               other ways of saying the same type

char
signed char
unsigned char
signed short int        short, signed short, short int
unsigned short int      unsigned short
signed int              int, signed (or nothing, in some cases)
unsigned int            unsigned
signed long int         long, signed long, long int
unsigned long int       unsigned long

(The order of the words is irrelevant.)

---

If you want to, you can think of this as types and modifiers, though
the standard does not speak of them that way. If so, here is how you
do it:

The types:

	char
	int

That's right. Only two.

The modifiers:

	unsigned        signed
	short           long

The first pair modifies char or int; the second int only. You can
specify only one of each pair.

---

Here are the characteristics of the types:

		signedness values
char            *          *
signed char     signed     no smaller integer range exists
unsigned char   unsigned   no smaller unsigned range exists
short           signed     contains signed char values
unsigned short  unsigned   contains unsigned char values
int             signed     contains short values
unsigned        unsigned   contains unsigned short values
long            signed     contains int values
unsigned long   unsigned   contains unsigned int values

* Char may be either signed or unsigned. However, it is always treated
as a distinct type. The characters in the source character set are
positive values, but anything else may be positive or negative.
There is no relationship between char and signed or unsigned char,
other than that they occupy the same amount of storage.

Each unsigned type must be able to represent the positive values of
its corresponding signed type. Signed and unsigned types must occupy
the same amount of storage.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.lang.c mailing list