Page 1 of 1

How eliminate conflict between basictypes.h and stdint.h?

Posted: Tue Jun 07, 2011 2:27 am
by yevgenit
I receive the following compilation error during porting of some free code:

Code: Select all

C:\nburn\gcc-m68k\m68k-elf\include/stdint.h:45: error: redefinition of typedef 'int8_t'
C:\nburn\include/basictypes.h:90: error: previous declaration of 'int8_t' was here
How can i eliminate the conflict without modifying a few tens files? The library (http://freemodbus.berlios.de/) has many ports, including Coldfire. It seems, that I missed some simple solution.

Some details are as the following.

NDDK Rel_2_5_2

C:\nburn\gcc-m68k\m68k-elf\include/stdint.h contain lines 44-48:

Code: Select all

#if __STDINT_EXP(SCHAR_MAX) == 0x7f
typedef signed char int8_t ;
typedef unsigned char uint8_t ;
#define __int8_t_defined 1
#endif
C:\nburn\include/basictypes.h contain lines 89-90:

Code: Select all

//TYPEDEFS needed for Freescale ETPU API
typedef signed char int8_t;

Re: How eliminate conflict between basictypes.h and stdint.h?

Posted: Tue Jun 07, 2011 6:30 am
by Chris Ruff
I have run into this problem many times working with other's code.

You can either

#undef _sum_typedef_
before
#include <built-in-header.h>

knowing that that header will redefine the typedef.

You can also alter the code coming in from the outside source in some obvious way

// RUFFSTUFF is not defined

#ifdef RUFFSTUFF
lose all of this stuff in here
#endif

so that you know what you altered.

I usually use some combination of both of the above to finally get through the compiler and on to the work at hand.

You have to be careful with the added code thinking differently about 16 vs. 32 bit integers. You need to read through all of their code and look for something that isn't compatible with the NB library and uCOS. You also need to look for endian issues especially near networking code- IP addresses and etc.

all in all - a PITA to bring in other's code, but ultimately worth it.

Chris

Re: How eliminate conflict between basictypes.h and stdint.h?

Posted: Tue Jun 07, 2011 9:45 am
by tod
I would probably standardize on one (let's say basictypes.h) and then I would wrap the conflicting section of the other one in a namespace. Then you just have to include <basictypes.h> in every file, if stdint.h gets included too it won't matter because it will be wrapped in a namespace you don't reference. If you had to get to it you could be explicitly including the namespace.

Re: How eliminate conflict between basictypes.h and stdint.h?

Posted: Tue Jun 14, 2011 6:10 am
by yevgenit
Thanks to tod and Chris Ruff for the suggestions.

After all, I encountered, that stdint.h is included in the single place: port.h. The library uses file port.h for general platform-specific includes and declarations. The implemented solution is modification of port.h:

- Replace

Code: Select all

#include <inttypes.h>
with

Code: Select all

#include <basictypes.h>
- Add pair

Code: Select all

#ifdef __cplusplus
extern "C"
{
#endif /* #ifdef __cplusplus */
and

Code: Select all

#ifdef __cplusplus
};
#endif /* #ifdef __cplusplus */
- Comment out a few redundant declarations:

Code: Select all

typedef uint8_t BOOL;
typedef int16_t SHORT;
typedef int32_t LONG;

Re: How eliminate conflict between basictypes.h and stdint.h?

Posted: Thu Jun 16, 2011 12:56 am
by yevgenit
More graceful solution would be modifying of Netburner's custom file basictypes.h to eliminate conflicts with ANSI C99 file inttypes.h.