Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > size of a function

Reply
Thread Tools

size of a function

 
 
asit dhal
Guest
Posts: n/a
 
      02-19-2007
Can any one write a code to measure the size of a function in gcc or vc
++ ?

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      02-19-2007
asit dhal wrote:

> Can any one write a code to measure the size of a function in gcc or vc
> ++ ?


What would you do with the answer [1], and why?

[1] To the question "what's the size of this function", not "Can anyone
write ...", to which the answer is clearly "yes", since
compiler-writers exist.

--
Chris "electric hedgehog" Dollin
Meaning precedes definition.

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-19-2007
In article <(E-Mail Removed) .com>,
asit dhal <(E-Mail Removed)> wrote:
>Can any one write a code to measure the size of a function in gcc or vc
>++ ?


Maybe -- but not in standard C.

You haven't really defined what is included in "the size" of
a function. If the function has uninitialized static variables,
then do you include the size of the automatic-initialized-to-zero
region used? If the function has initialized static variables,
then do you include the size of the initialization block (which
might be in a completely different code segment and might happen
to merge initializations of multiple variables from different
functions)? On architectures that are not stack-oriented, do you
include the size of the caller save area? Does "the size" of
the function include any temporary non-heap (e.g., stack) required
for it to execute?

If an optimizer detects common code between the function and
a different function, it could merge the two paths together
as long as it had some method of determining when to split apart
again (and if the code was the tail end of the code, that might
just be the "return from subroutine" code.) When code overlaps like
that, which of the functions do you count the size against?

--
All is vanity. -- Ecclesiastes
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      02-19-2007

"asit dhal" <(E-Mail Removed)> wrote in message
> Can any one write a code to measure the size of a function in gcc or vc
> ++ ?
>


void fsize( void (*fptr)() )
{
unsigned char bigbuff[1024*32];
void (*tptr)() = ( void (*) ()) bigbuff;
int len;

for(len = 1024*32; len >= 0; len--)
{
printf("trying %d\n", len);
memcpy(bigbuff, fptr, len);
(*tptr)();
}
}

There's a sporting chance that the this will print out values until it
segfaults. The last value is the size of your function.

When the


 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      02-20-2007
On Feb 20, 9:53 am, "Malcolm McLean" <(E-Mail Removed)> wrote:
>
> void fsize( void (*fptr)() )
> {
> unsigned char bigbuff[1024*32];
> void (*tptr)() = ( void (*) ()) bigbuff;
> int len;
>
> for(len = 1024*32; len >= 0; len--)
> {
> printf("trying %d\n", len);
> memcpy(bigbuff, fptr, len);
> (*tptr)();
> }
>
> }
>
> There's a sporting chance that the this will print out values
> until it segfaults. The last value is the size of your function.


Not really, the second and subsequent memcpy's will have no effect.
You would do better (?) to memset the rest of the buffer to 0 or
some trap value in each case.

>
> When the


Been trying your program out?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments