curiosity question regarding __func__

D

djinni

howdy,

Can anyone tell me where the function name string is
stored when __func__ is used? I read that it is
basically like declaring a static const char[], but when
I compile the following code, I cannot see the string "foo"
anywhere in the executable, (I've determined this by
running the 'strings' command on the compiled executable.)


#include <stdlib.h>
#include <stdio.h>

static const char* foo(void);
static const char* food(void);

int main( void )
{
printf( "function name is \"%s\"\n", foo() );
printf( "function2 name is \"%s\"\n", food() );

return 0;
}

static const char* foo(void)
{
printf( "now in function \"%s\"\n", __func__ );
return __func__;
}

static const char* food(void)
{
static const char func[] = "food";
return func;
}

Here is the program output:

$ ./a.out
now in function "foo"
function name is "foo"
function2 name is "food"


Here is the output from 'strings':

$ strings a.out
/lib/ld-linux.so.2
libc.so.6
printf
_IO_stdin_used
__libc_start_main
__gmon_start__
GLIBC_2.0
PTRh
QVh(
function name is "%s"
function2 name is "%s"
now in function "%s"
food



I cannot see where the "foo" string is stored.
I don't beleive that "foo" is sharing space with
the string "food", because if the food() function
is removed, there still is no "foo".
Is there maybe an issue with the 'strings' command?
Did my compiler fart?


confused,

-dj
 
R

Roger Willcocks

djinni said:
howdy,

Can anyone tell me where the function name string is
stored when __func__ is used? I read that it is
basically like declaring a static const char[], but when
I compile the following code, I cannot see the string "foo"
anywhere in the executable, (I've determined this by
running the 'strings' command on the compiled executable.) ....
Is there maybe an issue with the 'strings' command?

See strings --help and in particular the -<number> argument:
 
A

Ajey B Kulkarni

Roger said:
djinni said:
howdy,

Can anyone tell me where the function name string is
stored when __func__ is used? I read that it is
basically like declaring a static const char[], but when
I compile the following code, I cannot see the string "foo"
anywhere in the executable, (I've determined this by
running the 'strings' command on the compiled executable.) ...
Is there maybe an issue with the 'strings' command?

See strings --help and in particular the -<number> argument:

- said:
confused,

-dj

check 'nm t'. I see both foo/food being stored in some offset. Probably
strings is ignoring this info. (As it happens to be just function name??).
Another thing is strings -a shows "food" being stored but not "foo". strings
is possibly dumb ;-))
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top