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.

[SOLVED] C typedef can't understand

Status
Not open for further replies.

saur

Member level 2
Member level 2
Joined
Feb 23, 2012
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,621
Can anyone help me, as to what the following code snipped means?

Code:
typedef void (*XilExceptionHandler) (void *data);
 

typedef facility allows us to define a new nam for an existing data type...... here in the above expression When this exception handler function is called, the parameter Data pointer contains the same value as you provided when you registered the handler.
 
  • Like
Reactions: saur

    saur

    Points: 2
    Helpful Answer Positive Rating
Typedef of a function pointer.
 
  • Like
Reactions: saur

    saur

    Points: 2
    Helpful Answer Positive Rating
Hi debabrta kar
Thanks for the reply.

In the example code: they are using the data type XilExceptionHandler for a value Handler.

So does it mean the Handler contains void data as the Data pointer points to a void type??

Thanks
Saurabh
 

In the code snippet
Code:
 typedef void (*XilExceptionHandler) (void *data);
the XilExceptionHandler has been defined as a pointer to function which takes a void pointer a input parameter and returns nothing, according to what I've understood. Pls correct me if I'm wrong...

Now if I use it as follows:
Code:
XilExceptionHandler SendHandler;
Inst->Sendhandler = (XilExceptionHandler) stub;
where SendHandler defined above is an element of structure variable Inst
and stub is defined as
Code:
 static void stub (void)

My main doubt is when we typecast the stub function to a pointer to a function, it should pass the address of the function to the SendHandler function pointer in the structure, but can't understand how it does so?
 

Although it's problematic to discuss incomplete code snippets, two points are obviously wrong:
- a function pointer can be assigned to the address of a function, not the function itself
- void (pf1 *)(void) and void (pf2 *)(void * data) aren't assignment compatible
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top