size of a function

Discussion in 'C++' started by bob@coolgroups.com, Apr 2, 2006.

  1. Guest

    is there any way to get the size of a function in c++?

    for instance, you might want to move it in memory or something.
    , Apr 2, 2006
    #1
    1. Advertising

  2. * :
    > is there any way to get the size of a function in c++?


    Not in standard C++.


    > for instance, you might want to move it in memory or something.


    Use assembly language for that.



    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Apr 2, 2006
    #2
    1. Advertising

  3. Jack Klein Guest

    On 2 Apr 2006 01:51:08 -0800, wrote in
    comp.lang.c++:

    > is there any way to get the size of a function in c++?
    >
    > for instance, you might want to move it in memory or something.


    Not only can't you get the size of a function in standard C++, you
    can't "move it in memory" either. I don't know whether you can "or
    something" the function or not, you'll have to be more specific.

    There are exactly two and only two things you can do with a function
    in C++: call it, or take its address.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Apr 2, 2006
    #3
  4. krbyxtrm Guest

    In Win32 and for all exported/imported functions there are ways to get
    function name and address, you can use your target function alignment
    with other functions to determine size (typically address is just
    DWORD).

    If function which resides only in the exe, use "GetProcAddress" (see
    MSDN for Info)
    it will return (again) the address of your target function, but then
    not the size, but you may use the its parameters, and data inside it to
    somehow "guess" the size.

    BTW, if its exported/imported it would be much easier.
    ---
    KRBY
    krbyxtrm, Apr 2, 2006
    #4
  5. * krbyxtrm:
    > [off-topic] In Win32...


    Please don't post off-topic comments.

    Please read the FAQ and the monthly welcome message.

    Thanks in advance.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Apr 2, 2006
    #5
  6. john chung Guest

    It is possible to get some "idea" the size of it.
    Try pointer arithmetic.

    pointer to func2*next function of func1* - pointer to func1
    of course it is NOT accurate.......

    The best way is to get the compiler to generate a map for you for the
    given source code. Getting the runtime size of the function is
    difficult to calculate or almost impossible when you think of
    it......... Do you end the function with a single ret or multiple ret?
    It also a question you should answer. It is possible but can be
    complicated at best. You have to severly limit you kind of function
    that you can write.

    In short avoid using such implementation specifics.... Unless you
    are a virus writer!

    john

    On 2 Apr 2006 01:51:08 -0800, wrote:

    >is there any way to get the size of a function in c++?
    >
    >for instance, you might want to move it in memory or something.
    john chung, Apr 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Madhanmohan S
    Replies:
    5
    Views:
    7,734
    Madhanmohan S
    Sep 3, 2004
  2. Andreas Klemt
    Replies:
    6
    Views:
    11,060
    Peter Theill
    Nov 28, 2004
  3. =?Utf-8?B?QmlkYXJrb3Rh?=

    How to set the DataGrid Row Size to a fixed size.

    =?Utf-8?B?QmlkYXJrb3Rh?=, May 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    820
    =?Utf-8?B?QmlkYXJrb3Rh?=
    May 19, 2005
  4. Neil Zanella
    Replies:
    4
    Views:
    483
    Gianni Mariani
    Oct 9, 2003
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,562
    Michael Jung
    May 25, 2008
Loading...

Share This Page