Reputation: 3
I am trying to develop a C application, using some library and function i can't modify(they are provided by someone else).
Here is my code block where the problem occurs:
unsigned short errSV;
unsigned short sgdSessFSE;
errSV = SRT_ControleComplet_S(sgdSessFSE);
And here is how SRT_ControleComplet_S is declared in the header file:
typedef unsigned short (API_ENTRY FARPTR SRT_ControleComplet_S) (unsigned short NumeroSession);
Where API_ENTRY and FARPTR are defined as
#ifndef API_ENTRY
#define API_ENTRY
#endif
#ifndef FARPTR
#define FARPTR *
#endif
When compiling, I have the following error:
error: expected expression before SRT_ControleComplet_S
I already have encountered this problem with a ], } and other special character that were in the wrong place, but here I don't really know how to fix it.
Does anyone know what should I do?
=============== UPDATE
Well, the problem is solved almost by itself... apparently the header i got was not the last version, so someone gave it to me.
Here is the last version:
typedef unsigned short (API_ENTRY TFCTSRTCONTROLECOMPLET_S)
(unsigned short NumeroSession);
extern TFCTSRTCONTROLECOMPLET_S SRT_ControleComplet_S;
which is much better now, with the extern.
Thank you for helping me and for your advices!
Upvotes: 0
Views: 1086
Reputation: 1163
So what @Lelanthran is saying is to change your code thus:
unsigned short errSV;
unsigned short sgdSessFSE;
SRT_ControleComplet_S fn /* = something */ ;
errSV = fn(sgdSessFSE);
That should at least compile.
Since SRT_ControleComplet_S
is a type, the compiler has no information about the function to call, only it's parameters and return type, so you need to initialise your fn
variable to point to a function to be called. So, you should find that your library provides one or more API entry point function that has the same arguments and return type, and that's what you put in where I put the /* = something */
.
If you want more specific help, you'll need to tell us more about the library, maybe upload the headers.
Upvotes: 0
Reputation: 1529
That is not a function that can be called, it is a type (as specified in the typedef). For example:
typedef int (*foo) (int bar);
int func1 (int bar) {
return bar + bar;
}
int func2 (int bar) {
return bar * bar;
}
int main (void) {
foo f_ptr; // declare a variable
f_ptr = func1; // set variable to func1
f_ptr (10); // returns 20
f_ptr = func2; // set variable to func2
f_ptr (10); // results in 100
}
As you can see above, "foo" is not a function but it is the typename of a function. The other stuff in all caps is #defined somewhere and since I don't know what the preprocessor does with it I am unable to comment on it other than to say it must result in at least an asterisk.
Upvotes: 1