UINT32的定义有什么问题? [英] What's wrong with the definition of UINT32?

查看:554
本文介绍了UINT32的定义有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码段:



I've the following code snippet:

typedef unsigned long UINT32;

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







我使用VS2012编译错误/ C ++编译它:






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

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 "

typedef unsigned long UINT32;"



我有错误:




I've got error:

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





这太荒谬了。在前一种情况下,它抱怨我重新定义了UINT32,它已经在C:\Program Files(x86)\ Windows Kits \8.0 \Include \shared \ basetsd.h中定义,虽然我没有在我的代码中查找此头文件的任何内容。



在以后的情况下,似乎抱怨UINT32未定义。

让我困惑的是什么如果我在我的文件中定义UINT32,它抱怨我重新定义它。如果我删除UINT32定义,它抱怨UINT32是未定义的术语。



任何人都知道为什么并且可以帮我怎么做?



我尝试了什么:



我搜索了错误信息,发现解释不符合我的情况。我检查了我的代码,但没有找到任何包含C:\Program Files(x86)\ Windows Wits\8.0\Include\shared\basetsd.h。它是如何进入讨论的?



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?

推荐答案

您将文件 GlobalData.h 包含在不同的源文件中。其中一些包括 basetsd.h (当包含 GlobalData.h 时会抛出重新定义错误)而有些则不包含(当<$ c时会抛出丢失的类型错误) $ c> UINT32 未在 GlobalData.h 中定义。



解决方案是包含 basetsd.h GlobalData.h 之上并删除类型定义。
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.


首先,UINT32是unsigned int,而不是unsigned long 。这可能是你得到重新定义错误的原因。


您可以将您的定义放在 #ifndef 保护块中。

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.
#ifndef UINT32
#define UINT32 unsigned int
#endif


这篇关于UINT32的定义有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆