It is easy to cast something to an elementary type:
write the name of the new type (for example, int) in brackets before the expression you wish to cast.
It is not quite so obvious how to cast to a more complicated type.
Say you have a pointer to a void that you know actually contains a function pointer.
How do you do the typecast and call the function all in one statement?
Even complicated casts can be written following this three-step process.
1. Look at the declaration of the object to which you wish to assign the casted result.
2. Remove the identifier (and any storage class specifiers like extern), and enclose what
remains in parentheses.
3. Write the resulting text immediately to the left of the object you wish to cast.
No comments:
Post a Comment