views:

137

answers:

5

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

`

A: 

This line of code:

static int cardinit(cardinfo *card);  

should be added after the definition of your cardinfo structure.

+7  A: 

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

struct cardinfo;
static int cardinit(struct cardinfo *card);
Vladimir
Beat me to it ;)
Chris
In C90, it would be necessary to say `static int cardinit(struct cardinfo *card);` with the forward declaration. Is that still true in C99?
David Thornley
compiled dummy code as c++ initially, changed that to c and yes, it seems 'struct' is required indeed
Vladimir
+3  A: 

You need to put the line

static int cardinit(cardinfo *card);

after the definition of the cardinfo structure.

Martin B
A: 

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

Paul Tomblin
A: 

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 link has a nice article on when full declarations are not required.

Praveen S