Stdint.h and sdl_config_win32.h conflict

Dear All,

I’m using MSVC 2005 and my source oode used stdint.h and SDL. When I’m compiling
my application I get the error:

error C2371: ‘int8_t’ : redefinition; different basic types

This is because the sdl_config_win32.h defines
typedef signed __int8 int8_t;

and the stdint.h defines
typedef __int8 int8_t;

but I cannot change the stdint.h or else I get problems.

How can I solve this problem.

If (one of) the header file(s) is not too long, or you have the header(s) added
to your own project, you can open them up, and put something like this:

For stdint.h:----------------------------------
typedef __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef __int8 int8_t;
#endif //int8_t

For sdl_config_win32:

typedef signed __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef signed __int8 int8_t;
#endif //int8_t

Only doing one of them should work. But remember to include the one that has
the guards (preprocessor keywords) after you include the one without the
guards. Otherwise the one with the guards will see ‘It wasn’t defined’ and
define it whilst the other one doesn’t have defines at all and will try to
define it again, which results into the same error.

I haven’t tested this, but I assume it should work. If it doesn’t, you can try
removing one of the typedefs from either one of the header files (if you have
access to the header files, that is).

If (one of) the header file(s) is not too long, or you have the header(s) added
to your own project, you can open them up, and put something like this:

For stdint.h:

typedef __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef __int8 int8_t;
#endif //int8_t

Typedefs are not “defined” in this sense, so this will fail. Also, I
don’t recommend changing system header files except as a last resort.

For sdl_config_win32:

typedef signed __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef signed __int8 int8_t;
#endif //int8_t

Changing this one as a workaround for the time being sounds okay to me,
but this won’t work for the same reason. Also, you should use /* comments
*/ here, not // comments (though it doesn’t matter too much unless you’re
trying to come up with a proper fix to commit). For a workaround, I’d
just write something like:On Thu, 18 Dec 2008, Creature wrote:


/* WORKAROUND – disabling this line until fixed by SDL team -yourname */
#if 0
typedef signed __int8 int8_t;
#endif

I won’t try to come up with a proper fix because I don’t have enough
information. Someone needs to answer the question: why is this typedef in
sdl_config_win32.h in the first place. Once you know that, you can figure
out a proper fix, rather than a workaround.

Only doing one of them should work. But remember to include the one that has
the guards (preprocessor keywords) after you include the one without the
guards. Otherwise the one with the guards will see ‘It wasn’t defined’ and
define it whilst the other one doesn’t have defines at all and will try to
define it again, which results into the same error.

I haven’t tested this, but I assume it should work. If it doesn’t, you can try
removing one of the typedefs from either one of the header files (if you have
access to the header files, that is).

Yes, that.

-Crystal

Thanks for your reactions. I remember that I saw some problems with this
by the FFMPEG community but no real answer. I solved it by removing the
word signed in the sdl_config_win32.h and then compiled the SDL again
for MSVC2005.


#if defined(GNUC) || defined(DMC)
#define HAVE_STDINT_H 1
#elif defined(_MSC_VER)
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else

Until now the SDL works and my project compiles but it’s not nice. It’s
better to know from the SDL community why the signed is there anyway.

With kind regards

Crystal Jacobs wrote:> On Thu, 18 Dec 2008, Creature wrote:

If (one of) the header file(s) is not too long, or you have the
header(s) added
to your own project, you can open them up, and put something like this:

For stdint.h:

typedef __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef __int8 int8_t;
#endif //int8_t

Typedefs are not “defined” in this sense, so this will fail. Also, I
don’t recommend changing system header files except as a last resort.

For sdl_config_win32:

typedef signed __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef signed __int8 int8_t;
#endif //int8_t

Changing this one as a workaround for the time being sounds okay to me,
but this won’t work for the same reason. Also, you should use /*
comments */ here, not // comments (though it doesn’t matter too much
unless you’re trying to come up with a proper fix to commit). For a
workaround, I’d just write something like:


/* WORKAROUND – disabling this line until fixed by SDL team -yourname */
#if 0
typedef signed __int8 int8_t;
#endif

I won’t try to come up with a proper fix because I don’t have enough
information. Someone needs to answer the question: why is this typedef
in sdl_config_win32.h in the first place. Once you know that, you can
figure out a proper fix, rather than a workaround.

Only doing one of them should work. But remember to include the one
that has
the guards (preprocessor keywords) after you include the one without the
guards. Otherwise the one with the guards will see 'It wasn’t defined’
and
define it whilst the other one doesn’t have defines at all and will
try to
define it again, which results into the same error.

I haven’t tested this, but I assume it should work. If it doesn’t, you
can try
removing one of the typedefs from either one of the header files (if
you have
access to the header files, that is).

Yes, that.

-Crystal

Hello,

MSVC < 2005 does not provide any C99 support, hence the “need” for SDL
to define these types.

Ironically, SDL doesn’t actually use them; it simply creates new
typedefs, eg Uint16.

IMO, these non-standard typedefs should be removed in favour of the
C99-style ones… but that’s a 2.0, rather than a 1.x change.

Eddy

2008/12/18 Jan :>

Thanks for your reactions. I remember that I saw some problems with this by
the FFMPEG community but no real answer. I solved it by removing the word
signed in the sdl_config_win32.h and then compiled the SDL again for
MSVC2005.


#if defined(GNUC) || defined(DMC)
#define HAVE_STDINT_H 1
#elif defined(_MSC_VER)
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else

Until now the SDL works and my project compiles but it’s not nice. It’s
better to know from the SDL community why the signed is there anyway.

With kind regards

Crystal Jacobs wrote:

On Thu, 18 Dec 2008, Creature wrote:

If (one of) the header file(s) is not too long, or you have the header(s)
added
to your own project, you can open them up, and put something like this:

For stdint.h:

typedef __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef __int8 int8_t;
#endif //int8_t

Typedefs are not “defined” in this sense, so this will fail. Also, I
don’t recommend changing system header files except as a last resort.

For sdl_config_win32:

typedef signed __int8 int8_t;

Becomes:

#if !defined(int8_t)
typedef signed __int8 int8_t;
#endif //int8_t

Changing this one as a workaround for the time being sounds okay to me,
but this won’t work for the same reason. Also, you should use /* comments
*/ here, not // comments (though it doesn’t matter too much unless you’re
trying to come up with a proper fix to commit). For a workaround, I’d just
write something like:


/* WORKAROUND – disabling this line until fixed by SDL team -yourname */
#if 0
typedef signed __int8 int8_t;
#endif

I won’t try to come up with a proper fix because I don’t have enough
information. Someone needs to answer the question: why is this typedef in
sdl_config_win32.h in the first place. Once you know that, you can figure
out a proper fix, rather than a workaround.

Only doing one of them should work. But remember to include the one that
has
the guards (preprocessor keywords) after you include the one without the
guards. Otherwise the one with the guards will see 'It wasn’t defined’
and
define it whilst the other one doesn’t have defines at all and will try
to
define it again, which results into the same error.

I haven’t tested this, but I assume it should work. If it doesn’t, you
can try
removing one of the typedefs from either one of the header files (if you
have
access to the header files, that is).

Yes, that.

-Crystal


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

IMO, these non-standard typedefs should be removed in favour of the
C99-style ones… but that’s a 2.0, rather than a 1.x change.

agreed. i also asked about it a while ago for any version but didnt push it.