2010-08-06 56 views
2

正如標題所說,在編譯時不斷收到此錯誤。從谷歌上搜索這個錯誤的人說,這是不是在頭文件中聲明,但我的功能是靜態的,它不是在頭文件,我原型it.`編譯器錯誤在'*'標記之前的C:expected')'

#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; 
} 

`

回答

16

cardinfo結構在錯誤行上仍未定義。把預先聲明之前:

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

打我吧;) – 2010-08-06 16:01:04

+1

在C90中,有必要說static int cardinit(struct cardinfo * card);'帶前向聲明。這在C99中仍然如此嗎? – 2010-08-06 16:03:02

+0

最初編譯爲虛擬代碼爲C++,將其改爲c並且是,看起來'struct'確實是必需的 – Vladimir 2010-08-06 16:11:48

8

這行代碼:

static int cardinit(cardinfo *card); 

應該在cardinfo結構的定義之後添加。

4

你需要放線

static int cardinit(cardinfo *card); 

cardinfo結構的定義之後。

1

在那一行,編譯器還不知道cardinfo是一個結構。在它的前面加上struct cardinfo;

0

你已經聲明瞭一個函數,它有一個類型的輸入變量,當編譯器解析它時,它是不知道的。即結構定義遵循你的函數聲明。 所以,當你想編譯這樣的代碼時,請做一個結構的前向聲明。

在計算機程序中,前向聲明是一個標識符的聲明 (表示一個實體,如一個類型,一個變量或函數 )的量,程序員還沒有給出了完整的定義。

link有一個很好的文章,當不需要完整的聲明。

相關問題