Reputation: 21
From stdint.h the following
#ifndef int8_t
typedef signed char int8_t;
#define int8_t int8_t
#define INT8_MIN (-128)
#define INT8_MAX (127)
#endif
What does the #define int8_t int8_t
do or define ?
Upvotes: 2
Views: 2865
Reputation: 263237
It defines int8_t
as a macro whose existence can be tested with #ifndef int8_t
, presumably with the intent of preventing int8_t
from being defined twice.
I don't know why it does it this way. It would make more sense to use a single include guard around the entire <stdint.h>
header.
(In a previous version of this answer, I asserted that the implementation is non-conforming, since it defines int8_t
as a macro. Doing so is unnecessary, but not invalid. Quoting N1570 7.1.3:
Each identifier with file scope listed in any of the following subclauses (including the future library directions) is reserved for use as a macro name and as an identifier with file scope in the same name space if any of its associated headers is included.
So the identifier int8_t
is reserved for use as a macro, and the implementation's macro definition is permitted.)
What implementation is this from?
Upvotes: 1