Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pointer of function in c

Status
Not open for further replies.

abolfazlk873

Junior Member level 3
Joined
Dec 2, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,488
hi everybody
i am new in c programming, and i have a question about pointer of functions.
consider the code shown below:
Code:
uint8_t  [COLOR="#FF0000"]*[/COLOR]([COLOR="#0000FF"]*[/COLOR]GetConfigDescriptor)( uint8_t speed , uint16_t *length);
in the code there is two pointer for function in color of red and blue.
i know the task of the blue pointer but i don't know the task of red pointer.

what the task of red pointer?
i show the complete code below:
Code:
typedef struct _Device_cb
{
  uint8_t  (*Init)         (void *pdev , uint8_t cfgidx);
  uint8_t  (*DeInit)       (void *pdev , uint8_t cfgidx);
 /* Control Endpoints*/
  uint8_t  (*Setup)        (void *pdev , USB_SETUP_REQ  *req);  
  uint8_t  (*EP0_TxSent)   (void *pdev );    
  uint8_t  (*EP0_RxReady)  (void *pdev );  
  /* Class Specific Endpoints*/
  uint8_t  (*DataIn)       (void *pdev , uint8_t epnum);   
  uint8_t  (*DataOut)      (void *pdev , uint8_t epnum); 
  uint8_t  (*SOF)          (void *pdev); 
  uint8_t  (*IsoINIncomplete)  (void *pdev); 
  uint8_t  (*IsoOUTIncomplete)  (void *pdev);   

  uint8_t  [COLOR="#FF0000"]*[/COLOR]([COLOR="#0000FF"]*[/COLOR]GetConfigDescriptor)( uint8_t speed , uint16_t *length); 
#ifdef USB_OTG_HS_CORE 
  uint8_t  [COLOR="#FF0000"]*[/COLOR]([COLOR="#0000FF"]*[/COLOR]GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);   
#endif

#ifdef USB_SUPPORT_USER_STRING_DESC 
  uint8_t  [COLOR="#FF0000"]*[/COLOR]([COLOR="#0000FF"]*[/COLOR]GetUsrStrDescriptor)( uint8_t speed ,uint8_t index,  uint16_t *length);   
#endif  
  
} USBD_Class_cb_TypeDef;
 

the called function is returning char * or uint8_t * or

the function is returning pointer of uint8_t.
 

ok, but in C programming when i decided to define pointer to the function like below:
Code:
int cmp(const char *, const char*));

pointer to this function is like below:
Code:
#include "string.h"
.
.
.
.
.
int ([COLOR="#0000FF"]*[/COLOR]p)(const char *, const char*);
p=strcmp;

but in this code there is no red pointer and the code is work well.
I want to know task of red pointer specified in the previous post.
 

Hi,
Because it is not returning pointer. it is returning an integer.

int cmp(const char *, const char*));

int (*p)(const char *, const char*);
p=cmp; // it replace as int (cmp)(const char *, const char*);=int cmp (const char *, const char*);


if the function is returning pointer

then

int *cmp(const char *, const char*));

int *(*p)(const char *, const char*);
 
Last edited by a moderator:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top