繁体   English   中英

错误:“类型名称”声明为返回函数的函数

[英]error: 'type name' declared as function returning a function

我正在使用avr-gcc为PID控制器开发一个小型库。尽管在头文件中声明了该函数并在.c文件中单独定义了该函数,但编译器仍抛出以下错误:

Compiling C: pid.c
avr-gcc -c -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -                 
funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-  
adhlns=./pid.lst  -std=gnu99 -MMD -MP -MF .dep/pid.o.d pid.c -o pid.o 
pid.c:5: error: expected declaration specifiers or '...' before '(' token
pid.c:5: warning: function declaration isn't a prototype
pid.c:5: error: 'type name' declared as function returning a function
pid.c:5: error: conflicting types for 'PID_init'
pid.h:23: error: previous declaration of 'PID_init' was here
pid.c: In function 'PID_init':
pid.c:5: error: parameter name omitted

pid.h的头文件内容如下:

#include<avr/io.h>
#include<util/delay.h>

#ifndef PID_CONTROLLER
#define PID_CONTROLLER
struct PIDCONTROL

{

float error;
float prev_error;
float Kp;
float Ki;
float Kd;                       
float pid;
float P;
float I;
float D;
float setpoint;

};

void PID_init(float,float,float,float,struct PIDCONTROL*);

float PID(float,struct PIDCONTROL*);                        

#endif

已声明函数的定义已在pid.c中进行,其中包含以下代码:

#include<avr/io.h>
#include<util/delay.h>
#include "pid.h"

void PID_init(float SP,float Kp,float Ki,float Kd,struct PIDCONTROL *a)

{

a->Kp=Kp;

a->Ki=Ki;

a->Kd=Kd;

a->pid=0;

a->setpoint=SP;

a->prev_error=0;

}


float PID(float PV,struct PIDCONTROL *a)

{

a->error=(a->setpoint)-PV;

a->P=(a->Kp)*(a->error);

(a->I)+=(a->Ki)*(a->error)*1.024;

a->D=(a->Kd)*((a->error)-(a->prev_error))/1.024;

a->pid=(a->P)+(a->I)+(a->D);

a->prev_error=a->error;

return(a->pid);

}

我不能仅仅弄清楚代码有什么问题。 感谢您的帮助。

avr/io.h文件还avr/common.havr/common.h ,其中包含以下小片段:

/*
    Stack pointer register.
        AVR architecture 1 has no RAM, thus no stack pointer.
        All other architectures do have a stack pointer. Some devices have only
            less than 256 bytes of possible RAM locations (128 Bytes of SRAM
            and no option for external RAM), thus SPH is officially "reserved"
            for them.
*/

# ifndef SP
    # define SP _SFR_MEM16(0x3D)
# endif

(实际上要复杂得多,它取决于您的体系结构具有多条路径,但是该缩减示例至少显示了实际问题所在 )。

它实际上是为SP定义一个预处理器宏,这意味着,当您尝试在代码中使用带有函数定义的代码时,该宏如下:

void PID_init(float SP,float Kp,float Ki,float Kd,struct PIDCONTROL *a)

您将实际得到的是:

void PID_init(float _SFR_MEM16(0x3D),float Kp,float Ki,float Kd,struct PIDCONTROL *a)

这将导致编译器阶段苦苦抱怨。

我实际上是一个合理的自我描述变量名的mySP ,因此通常会选择比SP更详细的内容,但是即使将其设置为mySP ,您也可能会发现它可以解决当前的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM