【问题标题】:how to get rid of Microchip pic16f877A main redefined error?如何摆脱 Microchip pic16f877A 主重定义错误?
【发布时间】:2016-10-08 18:43:52
【问题描述】:

我是微芯片家族的新手。我试过下面的程序,

#include<pic.h> 
#include <stdio.h>
__CONFIG(0x1932);
void main() 
{ 
TRISA=0x00;
 PORTA=0x01; 
PORTA=0x02; 
PORTA=0x04; 
PORTA=0x08; 
PORTA=0x10;
 PORTA=0x20; 
PORTA=0x40; 
}    

但我得到了错误:

错误 [237] C:\Users\mathishara\Desktop\project_mplab\alternative.c; 9. 重新定义函数“_main”。

我该怎么办。

【问题讨论】:

  • 您缺少获得完整答案的信息。你用的是什么编译器?您使用的是哪个版本的编译器?编译期间哪些优化处于活动状态?发布完整的编译输出,重新定义的错误通常会有另一行,就像之前在这里定义的那样。

标签: microchip


【解决方案1】:

Main应该定义为

int main(void)

任何不带参数的函数都应该将void 作为其参数列表。

有关进一步讨论,请参阅 main() function in CWhat should main() return in C and C++?。对于嵌入式应用程序,“普通”参数列表int main(int argc, char *argv[]) 没有多大意义,所以void 就可以了。

【讨论】:

    【解决方案2】:

    在以下情况下可能会发生此错误:

    1. 函数定义与其原型不匹配

    例如

    int fun_prot();     /* the function prototype is missing the parameter - "int" */
    
    int fun_prot(int a)
    {
        ...
    }
    
    1. 如果函数在同一个模块中有多个定义

    函数重载在 C 中是非法的,会触发重定义错误。 例如:

    int twice(int a)
    {
        return a*2;
    }
    
    long twice(long a)      /* only one prototype & definition of twice can exist and this will trigger a redifinition error */
    {
        return a*2;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多