Reputation: 7024
I have a portable definition of types in a header of a project that i aim to compile on multiple platforms. I'm using the following typedefs:
#ifndef PLATFORM_H
#define PLATFORM_H
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed int int16_t;
typedef unsigned int uint16_t;
typedef signed long int int32_t;
typedef unsigned long int uint32_t;
typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;
#endif
This header is platform-specific, so i have a similar declaration for every platform, making sure that integers are always the same. However, in compiling, i get this:
conflicting types for ‘int32_t’
In file included from /usr/include/stdlib.h:314:0,
from platform.h:5,
from main.c:1:
/usr/include/x86_64-linux-gnu/sys/types.h:196:1: note: previous declaration of ‘int32_t’ was here
And other errors. What might be the cause? Can i override a typedef, or check for it's existence first?
Upvotes: 2
Views: 442
Reputation: 726559
You get an error because you picked names for your typedef
s that collide with names of types from the <stdint.h>
header.
Since you are looking for types that are already defined in stdint.h
, you might as well include it on platforms that provide this header.
Upvotes: 4