When I review a C program , I saw some code like this :
typedef int (*ibm_ldap_search_s)(LDAP *, char *, int , char *, char * [],int , LDAPMessage **);
What does this mean?
When I review a C program , I saw some code like this :
typedef int (*ibm_ldap_search_s)(LDAP *, char *, int , char *, char * [],int , LDAPMessage **);
What does this mean?
The constructions like rettype (* name )( arguments... )
are used for function pointers.
int (* f1 )(void);
f1
is a function pointer which takes no arguments and returns int.
typedef int (*ibm_ldap_search_s)(LDAP *, char *, int , char *, char * [],int , LDAPMessage **);
ibm_ldap_search_s
is a aliased type (ie. typedef). It aliases a function pointer which takes arguments: (pointer to LDAP, pointer to char, int value, pointer to char, pointer to pointer to char, int value and pointer to pointer to LDAPMessage) and returns an int. []
in function declarations is equal to *
, i mean char *[]
is the same as char **
.
Example:
typedef int (*ibm_ldap_search_s)(LDAP *, char *, int , char *, char * [],int , LDAPMessage **);
int ibm_ldap_search(LDAP *ldap, char *str1, int value1,
char *str2, char *pointer_to_strings[],
int value2, LDAPMEssages **messages) {
return 0;
}
int main() {
ibm_ldap_search_s bar = ibm_ldap_search;
int value = bar(NULL, NULL, 1, NULL, NULL, 2, NULL);
printf("Function returned $d\n", value);
return 0;
}