volatile能修饰数组么

wa2009 2012-07-17 09:17:40
如我定义一个数组DWORD tex[10];我想告诉编译器,其中的每个元素都是易变的,如何 用volatile来修饰?
volatile DWORD tex[10]和DWORD volatile tex[10]都是错的,貌似这样修饰的是数组名...求大神解释。
不胜感激..
...全文
1291 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
IVERS0N 2012-07-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

CV-qualifiers 修饰的是数组的元素 而不是数组本身。
c99标准如下:
If the specification of an array type includes any type qualifiers, the element type is soqualified,
not the array type.

c++标准如下:
A compound type (3.9……
[/Quote]

lihai
小菜菜 2012-07-25
  • 打赏
  • 举报
回复
可以,就当做const的用法就可以。。能用const的就能用volatile
Caworb 2012-07-22
  • 打赏
  • 举报
回复
extern都可以修饰数组甚至模板类变量之类的!volatile为什么不可以?
3楼标准直接秒杀我等庶民…
fzamygsd 2012-07-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
CV-qualifiers 修饰的是数组的元素 而不是数组本身。
c99标准如下:
If the specification of an array type includes any type qualifiers, the element type is soqualified,
not the array type.

c++标准如下:
A compound type (3.9.……
[/Quote]
授之以鱼不如授之以渔,
大神们这些标准在哪找的
wizard_tiger 2012-07-20
  • 打赏
  • 举报
回复
三楼正解!
可以的。
pengzhixi 2012-07-17
  • 打赏
  • 举报
回复
CV-qualifiers 修饰的是数组的元素 而不是数组本身。
c99标准如下:
If the specification of an array type includes any type qualifiers, the element type is soqualified,
not the array type.

c++标准如下:
A compound type (3.9.2) is not cv-qualified by the cv-qualifiers (if any) of the types from which it is compounded.Any cv-qualifiers applied to an array type affect the array element type, not the array type
pathuang68 2012-07-17
  • 打赏
  • 举报
回复
语法上不存在任何问题。
BlackGhost 2012-07-17
  • 打赏
  • 举报
回复
可以的,volatile DWORD tex[10]
ForestDB 2012-07-17
  • 打赏
  • 举报
回复
两种语法都可以(gcc通过),3L给出了标准,我给个简单的判断方法,首先就是优先级,将[]先计算得到的是数组元素,其次靠近谁修饰谁,这样一来,volatile修饰的就是(a[0]),即数组中的元素。

LZ可以说说你用的编译器。
W170532934 2012-07-17
  • 打赏
  • 举报
回复
可以的吧。3楼都给出标准了
sadgod 2012-07-17
  • 打赏
  • 举报
回复
楼上正解,这种细节只能随时查资料了。能背过的人,真厉害。

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧