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

Discussion to talk about software related topics only.
Post Reply
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

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

Post 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;
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
User avatar
Chris Ruff
Posts: 222
Joined: Thu Apr 24, 2008 4:09 pm
Location: topsail island, nc
Contact:

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

Post 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
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

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

Post 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.
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

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

Post 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;
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

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

Post by yevgenit »

More graceful solution would be modifying of Netburner's custom file basictypes.h to eliminate conflicts with ANSI C99 file inttypes.h.
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
Post Reply