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