Differences between version 13 and previous revision of CastingPointerToFunction.
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 13 | Last edited on Monday, May 15, 2006 2:48:05 pm | by AristotlePagaltzis | Revert |
Older page: | version 12 | Last edited on Sunday, November 14, 2004 12:24:34 pm | by AristotlePagaltzis | Revert |
@@ -1,6 +1,4 @@
-''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: