C语言 C 中的编译器错误:在“*”标记之前应为“)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3425547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:06:31  来源:igfitidea点击:

Compiler Error in C: expected ')' before '*' token

ccompiler-errors

提问by khop

As the title says, keep getting this error when trying to compile. From Googling this error people have said that it is not declared in the header file but my function is static and it is not in a header file, I prototyped it.`

正如标题所说,尝试编译时不断收到此错误。从谷歌搜索这个错误,人们说它没有在头文件中声明,但我的函数是静态的,它不在头文件中,我对其进行了原型设计。`

#include <recGbl.h>
#include <devSup.h>
#include <devLib.h>
#include <drvIpac.h>
#include <dbScan.h>
#include <epicsExport.h>

static int cardinit(cardinfo *card);   // <-- line that gives the error

typedef struct cardinfo{
  struct cardinfo *next;

  struct io_mem_read *pMem;   /* IP register (A16) mem address */
  word *rambase;             /* RAM conversion memory mem address*/

  int isconfigured;
  int doram;   /* 1 if we are using the RAM to output data.
          0 if we are writing to registers (AO style) */

  int cardnum;
  int vmeslotnum;
  int ipslotnum;


  /* these values mirror the hardware registers */
  word csr;
  word offset;
  word numconv;
  word clockrate;
  word vectnum;


  word dacval[MAXSIGNAL];

  word oldispresent;
  /* used to detect a reinsertion of a carrier card.
     see subroutine ispresent() below. */

  /* use to update process variables */
  IOSCANPVT ioscanpvt;
} cardinfo;

static int Hy8402init(int vmeslot, int ipslot, int clockrate) {
    cardinfo *card;

    card->vmeslotnum = vmeslot;
    card->ipslotnum = ipslot;
    card->cardnum = 1;

    card->clockrate = clockrate;
    card->vectnum = 10;

    cardinit(card);

return TRUE;
}

static int cardinit(cardinfo *card){
  word rprobe;
  int res;
  volatile word *ramptr;

  card->pMem= ipmBaseAddr(card->vmeslotnum,
              card->ipslotnum,ipac_addrIO);  
  if (card->pMem==NULL){
    printf("Error in %s",devstr);
    printf( "%s: Cannot determine base address\n",devstr);
    return FALSE;
  }

  res=devReadProbe(sizeof (word),(char *) card->pMem,(char *) &rprobe);
  if (res!=OK){
    printf("%s: NO DEVICE at %x (vmeslot %d, ipslot %d)\n",devstr,
       (int)card->pMem,
       card->vmeslotnum,card->ipslotnum);
    return FALSE;
  }
return TRUE;
}

`

`

回答by Vladimir

cardinfo struct is still undefined on the line with error. Put a forward declaration before it:

cardinfo struct 在有错误的行上仍未定义。在它之前放一个前置声明:

struct cardinfo;
static int cardinit(struct cardinfo *card);

回答by Vladimir

This line of code:

这行代码:

static int cardinit(cardinfo *card);  

should be added after the definition of your cardinfo structure.

应该在你的 cardinfo 结构定义之后添加。

回答by Martin B

You need to put the line

你需要把线

static int cardinit(cardinfo *card);

afterthe definition of the cardinfostructure.

定义cardinfo结构之后。

回答by Paul Tomblin

At that line, the compiler doesn't yet know that cardinfo is a struct. Precede it with the line struct cardinfo;

在这一行,编译器还不知道 cardinfo 是一个结构体。在它前面加上一行struct cardinfo;

回答by Praveen S

You have declared a function which has a input variable of a type which the compiler is not aware when it parses it. i.e the struct defintion follows your function declaration. So please do a forward declaration of the structure when you want to compile such code.

你已经声明了一个函数,它有一个类型的输入变量,编译器在解析它时不知道。即结构定义遵循您的函数声明。因此,当您要编译此类代码时,请对结构进行前向声明。

In computer programming, a forward declaration is a declaration of an identifier (denoting an entity such as a type, a variable, or a function) for which the programmer has not yet given a complete definition.

在计算机编程中,前向声明是程序员尚未给出完整定义的标识符(表示实体,如类型、变量或函数)的声明。

This linkhas a nice article on when full declarations are not required.

这个链接有一篇关于何时不需要完整声明的好文章。