Microchip
直播中

陈敏杰

7年用户 263经验值
私信 关注
[问答]

在数组中使用volatile类型得到错误常量表达式

我需要创建一些外部变量变量。然后在每个变量内从EPROM中获得一个值。然后将这些值组合在一个ArayHead文件中:TyBuffsStult{int值;} StutnValueStValuestMyTest1;EXTEND易失性设置值MyTest2;EXTEND易失性设置值MyTest3;源文件:易失性设置值MyTest1;易失性设置值MyTest2;易失性设置值MyTest3在这里,我从EpPROM MyTest2.Vale= DATAEEA Read Byter(22)中读取;/在这里,我从EPROM//I读取每个EEPROM值(来自易失性变量),以使它们在数组中。Gt;int *CuffMyValue[] = {MyTest1.Valuy,MyTest2.Value.};我得到错误常量表达式。需要N。我怎样才能改变它,使之有效?

以上来自于百度翻译


      以下为原文

    I need to create some extern volatile variables. Then inside each variable to get a value from epprom. and then to combine this values inside an array
Header File:
typedef struct
{
int Value;

}SetValues;

extern volatile SetValues Mytest1;
extern volatile SetValues Mytest2;
extern volatile SetValues Mytest3;
Source File:
volatile SetValues Mytest1;
volatile SetValues Mytest2;
volatile SetValues Mytest3;

Mytest1.Vale=DATAEE_ReadByte(21);//Here i'm reading from epprom
Mytest2.Vale=DATAEE_ReadByte(22);//Here i'm reading from epprom

// i need each eeprom values(from volatile variables) to get them inside an array
>int *CheckMyValue[]={Mytest1.Value,Mytest2.Value...};
I get error constant expression required. How can i change this to for make it work?

回帖(9)

李皓圳

2018-11-13 15:38:47
你想在数组中有值,就像你在评论中所说的吗?或者你想有一个指针数组到MyTestAtvices变量,比如你的数组声明用int类型*让人相信吗?如果你想要这些值,就这样做:如果你想要指针,你可以这样做:但是,我不认为有一个带有变量的MyTestCar变量的列表是非常有效的。考虑用数组替换它们。

以上来自于百度翻译


      以下为原文

     

 
Do you want to have the values in the array, like you are saying in the comment?
 
Or do you want to have an array of pointers to the Mytest variables, like your array declaration with type int * makes one believe?
 
 
If you want the values, just do it like that:
int CheckMyValue[]={Mytest1.Value, Mytest2.Value, Mytest3.Value };
 
If you want pointers you can do it like that:
int * CheckMyValue[]={&Mytest1.Value, &Mytest2.Value, &Mytest3.Value };
 
However, I don't think having a list of Mytest variables with numbers is really efficient. Consider replacing those also with an array.
举报

李涛

2018-11-13 15:57:18
char ar〔10〕;int x=21;(int f=0;f& lt;10;f++)A[f]=DATAEEA Read Byg(x++);是否有一个原因需要复制副本?

以上来自于百度翻译


      以下为原文

     
char ar[10];
 
int x=21;
for(int f=0;f<10;f++) ar[f]=DATAEE_ReadByte(x++);
 
Is there a reason why you need duplicate copies?
举报

杨玲

2018-11-13 16:09:16
您还没有显示真正的代码,但是这个错误通常意味着在文件范围内初始化了一个依赖于另一个对象的值的初始化。它与“不稳定”无关。

以上来自于百度翻译


      以下为原文

   
 
You haven't shown real code, but this error usually  means you've put an initialization at file scope that relies on the value of another object.  It has nothing to do with "volatile".
举报

李建宁

2018-11-13 16:17:54
@ GOT2015OH!非常感谢,这可以帮助我避免很多代码。但是,每个例子中的每个值如何读取每个位置呢?char ar〔10〕;int x=21;(int f=0;f& lt;10;f++)A[f]=DATAEEA Read Byg(x++);如何使用它与每个i值的组合?LyMyTest1.1.值OrMyTest2.值????

以上来自于百度翻译


      以下为原文

    @Gort2015 oh! thank you verymuch this helps me a lot to avoid much code. But How can each value take Read for each own location in your example?
 
 char ar[10];
 
int x=21;
for(int f=0;f<10;f++) ar[f]=DATAEE_ReadByte(x++);
 
How can i use it with conbination of each my value? 
Like Mytest1.Value or Mytest2.Value ???
举报

更多回帖

发帖
×
20
完善资料,
赚取积分