指针问题 [英] Problem with a pointer

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

问题描述

我的指针有点问题。


在我的项目中加入了一个.h。带有此声明的文件:


" #define pMDMA_D0_START_ADDR((void * volatile *)MDMA_D0_START_ADDR)"


如果我赋值(例如* pMDMA_S0_START_ADDR = 0x04000;)

编译器给我这两个警告:

" .\init.c",第105行:cc0513:{D}警告:类型为int的值不能

分配给类型为void *的实体的


* pMDMA_S0_START_ADDR = 0x04000;

^


" .\init.c",第105行:cc0152:{D}警告:转换非零

整数到

指针

* pMDMA_S0_START_ADDR = 0x04000;

^


为什么出现这些警告?


谢谢,Maurizio

Hi, I have a little problem with a pointer.

In my project is included an ".h" file with this declaration:

"#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"

If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000;) the
compiler give me these 2 warning:
".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
be
assigned to an entity of type "void *"
*pMDMA_S0_START_ADDR = 0x04000;
^

".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
integer to
pointer
*pMDMA_S0_START_ADDR = 0x04000;
^

Why appears these warnings?

thanks, Maurizio

推荐答案




mauri1106写道:


mauri1106 wrote:
我的指针有点问题。

在我的项目中包含了一个.h。具有此声明的文件:

" #define pMDMA_D0_START_ADDR((void * volatile *)MDMA_D0_START_ADDR)"

如果我指定一个值(例如* pMDMA_S0_START_ADDR = 0x04000;)


如何定义pMDMA_S0_START_ADDR?

编译器给我这两个警告:

" .\init.c" ,第105行:cc0513:{D}警告:类型为int的值不能
分配给类型为void *的实体
* pMDMA_S0_START_ADDR = 0x04000;

^

这可能是因为你的#define是pMDMA_D0_START_ADDR

^^

和错误你得到的分数为* pMDMA_S0_START_ADDR

^^


请发布实际代码!

还有一个建议是你可以查看预处理器输出

,看看你的代码如何扩展宏。


- Ravi

" .\init.c",第105行:cc0152:{D}警告:转换非零
整数指示
* pMDMA_S0_START_ADDR = 0x04000;
^
为什么会出现这些警告?

谢谢,Maurizio
Hi, I have a little problem with a pointer.

In my project is included an ".h" file with this declaration:

"#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"

If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000;) the
How is pMDMA_S0_START_ADDR defined ?
compiler give me these 2 warning:
".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
be
assigned to an entity of type "void *"
*pMDMA_S0_START_ADDR = 0x04000;
^
Thats probably because your #define is pMDMA_D0_START_ADDR
^^
and error you got points to *pMDMA_S0_START_ADDR
^^

Post the real code please !
One more suggestion is you could look at the pre-processor output
to see how your macro has expanded in the code.

- Ravi

".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
integer to
pointer
*pMDMA_S0_START_ADDR = 0x04000;
^

Why appears these warnings?

thanks, Maurizio






对不起,对于S0是正确的。在断言中!

I''m sorry, is correct with "S0" in assegnation!


mauri1106写道:
mauri1106 wrote:
我的指针有点问题。

" #define pMDMA_D0_START_ADDR((void * volatile *)MDMA_D0_START_ADDR)"


我假设您的标题中还包含以下内容:

#define MDMA_DO_START_ADDR 0x12345678


将来,请提供*完整*最小的示例,显示

问题(可编译,除非问题是它不能编译)。

如果我分配一个值(例如* pMDMA_S0_START_ADDR = 0x04000;)
编译器给我这两个警告:

" .\init.c",第105行:cc0513:{D}警告:类型为int的值不能
分配给类型为void *的实体
* pMDMA_S0_START_ADDR = 0x04000;


这很简单。 void *是一个通用的指针类型,所以当然你不能通过void *指针读取或写入
。你需要有一个指向

完整的已知类型的指针,例如int或char。

" .\init.c",第105行:cc0152:{D}警告:将非零
整数转换为
指针


这也很简单。由

C标准完全定义的唯一指针整数是0转换为空指针。对于其余的,它是实现定义的一个可能的定义是

没有足够大的整数类型来表示指针。

* pMDMA_S0_START_ADDR = 0x04000;


为什么会出现这些警告?
Hi, I have a little problem with a pointer.

In my project is included an ".h" file with this declaration:

"#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"
I assume that you also have something like the following in our header:
#define MDMA_DO_START_ADDR 0x12345678

In future, please provide a *complete* minimal example that shows the
problem (compilable, unless the problem is that it won''t compiler).
If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000;) the
compiler give me these 2 warning:
".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
be
assigned to an entity of type "void *"
*pMDMA_S0_START_ADDR = 0x04000;
That''s simple. void* is a generic pointer type, so of course you can''t
read or write through a void* pointer. You need to have a pointer to a
complete, known type, e.g. int or char.
".\init.c", line 105: cc0152: {D} warning: conversion of nonzero
integer to
pointer
That''s simple as well. The only integer to pointer fully defined by the
C standard is that 0 converts to a null pointer. For the rest, it is
implementation defined with one possible definition being that there is
no integer type large enough to represent pointers.
*pMDMA_S0_START_ADDR = 0x04000;
^

Why appears these warnings?




因为您编写了可怕的代码。我猜你正在尝试

直接访问硬件,但取决于你使用的操作系统(如果你使用的是你的b $ b)这可能是不可能的,但即使它是

编译器需要知道它试图访问的类型。

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,但它是真实的,我读了它。



Because you are writing terrible code. I''m guessing that you are trying
to access hardware directly, but depending on the OS you are using (if
you are using one) this may not be possible, but even if it is the
compiler needs to know the type of what it is trying to access.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


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

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