Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've the following code snippet:

C++
typedef unsigned long UINT32;

typedef struct
{
	char 		str[128];
	UINT32	mSec;
				
} SUB_SEQ_LINK;



I've got compilation error using VS2012/C++ to compile it:

C#
D:\programs\ATP-3\ATP3MMI\MMI\Include\GlobalData.h(294): error C2371: 'UINT32' : redefinition; different basic types
1>          C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h(76) : see declaration of 'UINT32'


But if I remove the line of "
C++
typedef unsigned long UINT32;"

I've got error:

C#
1>D:\programs\ATP-3\ATP3MMI\MMI\Include\GlobalData.h(299): error C2146: syntax error : missing ';' before identifier 'mSec'
1>D:\programs\ATP-3\ATP3MMI\MMI\Include\GlobalData.h(299): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


It's ridiculous. In the former case, it complained that I redefined UINT32, which is already defined at C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h, although I didn't find any inclusion in my codes for this header file.

In later case, it seems complaining that UINT32 is undefined.
What confuses me is that if I define UINT32 at my file, it complained I redefined it. If I remove UINT32 definition, it complained UINT32 is undefined term.

Anyone knows why and can help me how to do it?

What I have tried:

I googled the error message and found the explanation does not fit my situation. I examined my codes and I didn't find any inclusion for C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h. How come it comes into discussion?
Posted
Updated 24-Mar-16 6:03am

You are including your file GlobalData.h in different source files. Some of them include basetsd.h (which will throw a redefinition error when including GlobalData.h) and some do not (which will throw the missing type error when UINT32 is not defined in GlobalData.h).

The solution is to include basetsd.h on top of GlobalData.h and remove the type definition.
 
Share this answer
 
v2
Comments
Stan Huang 24-Mar-16 5:53am    
Actually, what I did is to port a VxWorks project into Windows. I still didn't do any significant updates. It means all inclusions must be for standard C or from VxWorks/Tornado. I didn't update code to include basetsd.h. That's the reason why I got confused why basetsd.h was included.

I can't find Global.h & basetsd.h in my files.
Jochen Arndt 24-Mar-16 6:05am    
Sorry, I used Global.h instead of GlobalData.h and basedts.h instead of basetsd.h. I will update the solution.

The file basetsd.h may be not included explicitely but by including other header files. AT least it is included accroding to the error message.
First off, UINT32 is an unsigned int, not unsigned long. That may be why you are getting redefinition errors.

You could put your definition inside a #ifndef protection block.
C++
#ifndef UINT32
#define UINT32 unsigned int
#endif
 
Share this answer
 
v2
Comments
PJ Arends 24-Mar-16 18:03pm    
Thanks Matt T Heffron for updating my answer. I posted from my phone and was unable to fix it myself.
Stan Huang 30-Mar-16 2:05am    
What you said is partially right: redefinition error came from defining as 'unsigned long', but it should be 'unsigned int'. UINT32 is defined by typedef, not #define, so it can't be dealt as you said. Instead, I used 'typedef unsigned int UINT32;' to deal with it. At least, it works. I still don't know why it complained 'undefined' if I removed such tyepdef.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900