Reputation: 6023
When I open /usr/include/stdint.h
I see things like
typedef signed char int8_t;
which means that every int8_t
is to be treated like signed char
. This let's me suspect that on my system signed char
is of size 8bit. (However the other way round would be more intuitive for me i.e. every signed char
has to be treated like int8_t
.) Where is the size of signed char
defined?
Upvotes: 1
Views: 50
Reputation: 153919
It's not. It's only guaranteed to be at least 8 bits (since it must be able to contain values in the range [-127, 127]
. And int8_t
is also not guaranteed to exist; it's only present on machines where char
is an 8 bit 2's complement.
Upvotes: 0
Reputation: 39370
The implementation of the compiler for a particular architecture chooses whatever authors wanted for the "normal" datatype sizes (within the limits). So in a way, it's set in code, but not in the part visible to your programs in any means.
Then it's formulated in terms of the standard types, so that the sizes match.
Upvotes: 0
Reputation: 36438
Short answer: no.
The sizeof fundamental types like char
(and therefore signed char
) is defined by your compiler, based on the target system architecture. They're not defined in code.
The typedef above means the opposite - it's defining a new type named int8_t
, in terms of the predefined char
type. On your system (as on most) char
is 8 bits wide, so it's the natural way to define an 8-bit integer type.
Upvotes: 1