1

Possible Duplicate:
The difference of int8_t, int_least8_t and int_fast8_t?

I'm a quite confused. I think... (correct me if I'm wrong)

u_int8_t = unsigned short ?
u_int16_t = unsigned int ?
u_int32_t = unsigned long ?
u_int64_t = unsigned long long ?

int8_t = short ?
int16_t = int ?
int32_t = long ?
int64_t = long long ?

Then what does int_fast8_t mean? int_fastN_t? int_least8_t?

Community
  • 1
  • 1
Lluís
  • 578
  • 1
  • 5
  • 10

2 Answers2

2

I writing where int is of 16-bit:

u_int8_t = unsigned char  
u_int16_t = unsigned int
u_int32_t = unsigned long int
u_int64_t = unsigned long long int 

int8_t =  char
int16_t = int 
int32_t = long int
int64_t = long long int   

Q: "Then what does int_fast8_t mean? int_fastN_t? int_least8_t?"

As dan04 states in his answer here:

Suppose you have a C compiler for a 36-bit system, with char = 9 bits, short = 18 bits, int = 36 bits, and long = 72 bits. Then

  • int8_t does not exist, because there is no way to satisfy the constraint of having exactly 8 value bits with no padding.
  • int_least8_t is a typedef of char. NOT of short or int, because the standard requires the smallest type with at least 8 bits.
  • int_fast8_t can be anything. It's likely to be a typedef of int if the "native" size is considered to be "fast".

If you are in Linux most these are defined in /usr/include/linux/coda.h. e.g.

#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
typedef signed char       int8_t;
typedef unsigned char       u_int8_t;
typedef short            int16_t;
typedef unsigned short     u_int16_t;
typedef int          int32_t;
typedef unsigned int       u_int32_t;
#endif  

And

#if defined(DJGPP) || defined(__CYGWIN32__)
#ifdef KERNEL
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef u_long ino_t;
typedef u_long dev_t;
typedef void * caddr_t;
#ifdef DOS
typedef unsigned __int64 u_quad_t;
#else 
typedef unsigned long long u_quad_t;
#endif
Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
2

These are all specified in the C99 standard (section 7.18).

The [u]intN_t types are generic types (in the ISO C standard) where N represents a bit width (8, 16, etc). 8-bit is not necessarily a short or char since shorts/ints/longs/etc are defined to have a minimum range (not bitwidth) and may not be two's complement.

These newer types are two's complement regardless of the encoding of the more common types, which may be ones' complement or sign/magnitude ( see Representation of negative numbers in C? and Why is SCHAR_MIN defined as -127 in C99?).

fast and least are exactly what they sound like, fast-minimum-width types and types of at least a given width.

The standard also details which type are required and which are optional.

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • In Linux system, I didn't find `int_fastN_t`. Why so? I search using `/usr/include$ grep 'int_fastN_t' * -R`. – Grijesh Chauhan Dec 08 '12 at 14:34
  • 1
    @Grijesh, there _are_ no `blahN_t` types, the `N` is a placeholder in the standard for 8, 16, and so on. Search for `int_fast8_t` instead - they should all be together (and referenced from `inttypes.h`). – paxdiablo Dec 08 '12 at 14:43
  • Yes, `int_fast8_t` present but in `stdint.h`...in my system declaration are in `coda.h`! - Thanks paxdiablo :) voted-up to you – Grijesh Chauhan Dec 08 '12 at 14:49
  • Sorry, my bad, `stdint` holds the types, `inttypes` holds the format specifiers for `printf/scanf`. – paxdiablo Dec 08 '12 at 14:53
  • ya I saw..But I got my answer ..thanks :) – Grijesh Chauhan Dec 08 '12 at 14:56
  • Note that the `fast` and `least` types are not optional; the exact width types (`int8_t` et al) are optional in the sense that if the implementation uses 9-bit `char`, there won't be an `int8_t` type. If the implementation supports an 8-bit integer type, `int8_t` is not optional. – Jonathan Leffler Dec 08 '12 at 20:04