curiosity question regarding __func__

Discussion in 'C Programming' started by djinni, Aug 12, 2003.

  1. djinni

    djinni Guest

    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
    djinni, Aug 12, 2003
    #1
    1. Advertising

  2. "djinni" <> wrote in message
    news:p...
    > 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
    Roger Willcocks, Aug 12, 2003
    #2
    1. Advertising

  3. Roger Willcocks wrote:

    > "djinni" <> wrote in message
    > news:p...
    > > 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 ;-))
    Ajey B Kulkarni, Aug 13, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chasdev

    __func__ macro emulation

    chasdev, Oct 27, 2003, in forum: C++
    Replies:
    2
    Views:
    1,311
    Samuele Armondi
    Oct 30, 2003
  2. Gonçalo Rodrigues

    Curiosity question on signatures

    Gonçalo Rodrigues, Mar 6, 2004, in forum: Python
    Replies:
    0
    Views:
    251
    Gonçalo Rodrigues
    Mar 6, 2004
  3. Replies:
    9
    Views:
    4,710
    Ancient_Hacker
    Oct 26, 2006
  4. Guillaume Dargaud

    On use of C99 __func__ macro

    Guillaume Dargaud, Dec 5, 2007, in forum: C Programming
    Replies:
    10
    Views:
    872
    Tor Rustad
    Dec 9, 2007
  5. none

    The variable __func__ in C89 in gcc

    none, May 18, 2011, in forum: C Programming
    Replies:
    24
    Views:
    1,497
    Tim Rentsch
    May 24, 2011
Loading...

Share This Page