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
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);
 

debabrta kar

Member level 5
Joined
May 20, 2013
Messages
86
Helped
7
Reputation
16
Reaction score
5
Trophy points
1,288
Location
india
Activity points
1,858
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

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,160
Helped
14,393
Reputation
29,050
Reaction score
13,144
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,322
Typedef of a function pointer.
 
  • Like
Reactions: saur

    saur

    Points: 2
    Helpful Answer Positive Rating

saur

Member level 2
Joined
Feb 23, 2012
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,621
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
 

saur

Member level 2
Joined
Feb 23, 2012
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,621
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?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,160
Helped
14,393
Reputation
29,050
Reaction score
13,144
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,322
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

Top