Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > curiosity question regarding __func__

Reply
Thread Tools

curiosity question regarding __func__

 
 
djinni
Guest
Posts: n/a
 
      08-12-2003
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


 
Reply With Quote
 
 
 
 
Roger Willcocks
Guest
Posts: n/a
 
      08-12-2003
"djinni" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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:

-<number> least [number] characters (default 4).

>
> confused,
>
> -dj


--
Roger


 
Reply With Quote
 
 
 
 
Ajey B Kulkarni
Guest
Posts: n/a
 
      08-13-2003
Roger Willcocks wrote:

> "djinni" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > 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:
>
> -<number> least [number] characters (default 4).
>
> >
> > confused,
> >
> > -dj

>
> --
> Roger


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 )





 
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
The variable __func__ in C89 in gcc none C Programming 24 05-24-2011 09:23 AM
On use of C99 __func__ macro Guillaume Dargaud C Programming 10 12-09-2007 01:45 AM
How to test for the existence of __func__? dave_140390@hotmail.com C Programming 9 10-26-2006 08:24 PM
Google vs. WebFerret (?) Curiosity Question Bay0Wulf Computer Support 5 12-06-2003 06:39 AM
__func__ macro emulation chasdev C++ 2 10-30-2003 10:25 AM



Advertisments