Pregunta

I am porting a windows assembly to linux. I have certain code to port. I am actually a newbie with C in linux. I know C fundamentals are the same yet!

typedef struct sReader
{
    pReaderAddRef addRef;
    pReaderDelRef delRef;
}pReader, *pSReader;

typedef long (*pReaderAddRef)(struct sReader *);
typedef long (*pReaderDelRef)(struct sReader **);

The above code give me the error 'pReaderAddRef' declared as function returning a function.

I understand the way callback functions work. But i dont really know how to resolve this error.

Kindly help.

¿Fue útil?

Solución

While I don't understand your original error message - I get

f.c:3:5: error: unknown type name ‘pReaderAddRef’
f.c:4:5: error: unknown type name ‘pReaderDelRef’

with your original code -

it seems you mixed up the order: in order to use the function pointers, you must have them defined.

struct sReader; // incomplete type, but ready to be used

//alternatively:
typedef struct sReader pReader, *pSReader; // taken from your edit, but these prefixes are misleading

typedef long (*pReaderAddRef)(struct sReader *); // or mytypename
typedef long (*pReaderDelRef)(struct sReader **);

struct sReader
{
    pReaderAddRef addRef; // Now you can use them
    pReaderDelRef delRef;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top