Differences between version 12 and revision by previous author of CastingPointerToFunction.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 12 | Last edited on Sunday, November 14, 2004 12:24:34 pm | by AristotlePagaltzis | Revert |
Older page: | version 11 | Last edited on Thursday, May 6, 2004 1:40:34 pm | by JohnMcPherson | Revert |
@@ -1,4 +1,6 @@
+''InNeedOfRefactor''
+
[C] is probably the only language you can do this in (except maybe [Forth]). Other languages either have no way of doing this, or don't treat data and code differently.
(Feel free to add examples for other languages here.)
Once you've got a pointer to your machine code (usually an array of bytes or ints), you need to cast it to the appropriate type and call it. Eg if you have a pointer to a function which takes a char *, you can call it like this: