【问题标题】:"Result of function call is ignored": CodeWarrior. Why is it ignored?“函数调用的结果被忽略”:CodeWarrior。为什么会被忽略?
【发布时间】:2021-02-26 10:22:58
【问题描述】:

这是我正在尝试构建的伪代码(ish)。

这是中断函数。按下开关 2 时,potval = 1。按下开关 3 时,potval = 2。每按下开关,potval 都会更新。

void interruptJ_function (void){ //if i change to int interruptJ_function, it says that it was expecting a void function

  if(Pim.pifj.byte & 0x01)  {   //switch2 is pressed

    potval = 1;
    
    Pim.pifj.byte |= 0x01;    //clear interrupt bit
    //return potval;   //doing this says the result is returned in void-result-function
    
  } 
  
  else if(Pim.pifj.byte & 0x02)  { //switch 3 is pressed
    potval = 2;

    Pim.pifj.byte |= 0x02;   //clear interrupt bit
    //return potval;
  }
  
  //return potval;
  
}

这是 main.c。

int potval;
unsigned int i;


void main ()
{
  adt(potval);   //Warning: Result of function call is ignored

  for (;;); //recurring loop until interrupt initiated
}

int adt(int potval, unsigned int i) {
  
  if(potval == 1){ 
    //for (;;){     
    while(potval==1){ //breaks when potval =2
      
      i= Atd0.atddr[0].d10;     //ATD bits
     
      light7segment(i); // ATD changes number on 7segment display
    
        m_delay(50);
    }
 } 
  
  else if (potval == 2){
    light7segment(10); //ATD turns off 7segment display
    
  } 

}

【问题讨论】:

  • 试试这个教程:raywenderlich.com/…
  • However, its keep saying "result of function call is ignored" on CodeWarrior. 和extern int 变量有什么关系并共享它?你是在问一些 XY 问题吗?
  • 您是否尝试过谷歌搜索,字面意思是“XY 问题”? google.com/search?q=XY+question
  • CodeWarrior 肯定会将诊断与特定的源代码行相关联吗?
  • 还有:诊断与共享变量有什么关系?

标签: c extern microprocessors


【解决方案1】:

当您调用具有返回值的函数但忽略检查该返回值时,Codewarrior 会发出此警告。就像你在这里做的那样:

adt(potval);

通常解决方案是(void) adt(potval);。

但在这种情况下不是,因为原因是一个更严重的错误,即函数int adt(int potval, unsigned int i) 没有return 一个值。在大多数 Codewarrior 目标系统上,这意味着调用者代码将从累加器中获取一些随机值,然后跑到树林里。如果您在编译器在不同的警告中说“预期返回”时注意,则可以避免此错误。

【讨论】:

  • 我明白了.. 只需将 adt 函数中的所有内容移至 main 函数即可修复错误吗?
  • @JoshuaPark 恐怕你的代码没有任何意义。您的参数数量也错误。为什么你有2个与参数命名相同的全局变量。等等。我会远离这个,从一本好的 C 编程书开始。 Codewarrior 和旧的飞思卡尔 MCU 并不是最友好的学习环境。
猜你喜欢
  • 2016-07-01
  • 2021-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2019-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多