size of a function

B

bob

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.
 
J

Jack Klein

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.
 
K

krbyxtrm

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.
 
A

Alf P. Steinbach

* krbyxtrm:
[off-topic] In Win32...

Please don't post off-topic comments.

Please read the FAQ and the monthly welcome message.

Thanks in advance.
 
J

john chung

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top