Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:54:21+00:00 2026-05-25T18:54:21+00:00

Ok so I’ve used function pointers for some time. I was trying to figure

  • 0

Ok so I’ve used function pointers for some time. I was trying to figure out if this was possible.

First. It IS possible to convert a function pointer into an array of bytes.

It is also possible to reconstruct that function with the bytes in that array.

I would like to save a function into an array of bytes, and lets say save it to a text file (func.dat). Then later read that text file and execute the particular function…
Is it possible? It seems it should be possible the only problem I run across is finding the size of the array that makes up the function.

Is there any way to do this?

int func()
{
    return 1+1;
}

int main()
{
    int (*foo)() = func;

    char* data = (char*)func;

    // write all the data
    char* copyFunc = new char[sizeof(func)];
    for(int i = 0; i < sizeof(func); i++)
        copyFunc[i] = data[i];

    int (*constructedFoo)() = (int (*)())copyFunc;

    return 0;
}

of course this code won’t compile because sizeof does not work for functions, does anyone know how to get the size of a function? Or the size of the function header/footer.

I have tried things like

int func()
{
    1+1;
    new char('}');
}

Then searched for the } char (as the end of the function) but that size doesn’t work.

If your wondering why I need it, it could be used for lets say, sending a function to a remote computer to execute (thinking of parallel processing) Or even saving a function in a file like in my first example to later be used, this can be helpful.

Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:54:22+00:00Added an answer on May 25, 2026 at 6:54 pm

    What you’re trying to do is not possible in C/C++. First of all, functions may not be contiguous in memory in the binary. So there’s no definite “size”.

    Secondly, you can’t just load it into another program and execute it because it will violate memory protection (among other things, like address space).

    Lastly (if you managed to get this far), all non-relative jumps and references in the function will likely be broken.

    EDIT:

    The way to go about sending code to remote computers is to send entire (compiled) binaries. Then have the local and remote machines communicate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I used javascript for loading a picture on my website depending on which small
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.