I am studying how the C language works. I can find definitions for types like int8_t
, intptr_t
, etc in <stdlib.h>
:
// Represents true-or-false values
typedef _Bool bool;
enum { false, true };
// Explicitly-sized versions of integer types
typedef __signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
// Pointers and addresses are 32 bits long.
// We use pointer types to represent virtual addresses,
// uintptr_t to represent the numerical values of virtual addresses,
// and physaddr_t to represent physical addresses.
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
typedef uint32_t physaddr_t;
However, I can't find the definition of type like char
. Thus my question is, where are int
and char
defined?
In which header file is char
defined?
Nowhere - char
is a builtin type, not a user-defined one. It's part of the core language. The same applies to int
.
Is there no definition at all of these builtin types?
There is. The standard does defines these builtin types.
Note that both char
and int
are also keywords, which means you can't use them as identifiers, because they have a reserved and already assigned use in the language.
The char
and int
types, among others, are not defined in any header file. They are built in types, meaning they are part of the core language. Their definitions are hardcoded into the compiler itself.
As to how the compiler defines what those types are, that is dictated by the C standard.
The definition of int
and char
can be found in section 6.2.5 (Types). For example, the definition of char
:
3 An object declared as type
char
is large enough to store any member of the basic execution character set. If a member of the basic execution character set is stored in achar
object, its value is guaranteed to be nonnegative. If any other character is stored in achar
object, the resulting value is implementation-defined but shall be within the range of values that can be represented in that type.
Definitions for the other types, as well as the minimum range of values for each type, follow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With