Penguin
Diff: CastingPointerToFunction
EditPageHistoryDiffInfoLikePages

Differences between version 2 and predecessor to the previous major change of CastingPointerToFunction.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 2 Last edited on Sunday, November 10, 2002 8:44:59 pm by PerryLorier Revert
Older page: version 1 Last edited on Wednesday, October 2, 2002 8:07:20 pm by JonPurvis Revert
@@ -6,5 +6,16 @@
  ((int (*)(char *)) p)("hello, world"); 
  
 The secret here is the parenthesis around the star. To declare a variable to hold the above, use this: 
  
- int (*p )(char *); 
+ int (*func_t )(char *);  
+  
+Another trick is:  
+ typedef int (*func_t)(char *);  
+  
+ int foo(char *x) {  
+ printf("%s",x);  
+ }  
+  
+  
+ func_t p = foo;  
+ return p("Narf!" );