On use of C99 __func__ macro

Discussion in 'C Programming' started by Guillaume Dargaud, Dec 5, 2007.

  1. Hello all,
    Is it the same thing to do those two things:

    #define WHERE printf("We are in %s", __func__)
    void Function(void) {
    WHERE;
    }

    And this:

    void Function(void) {
    #define WHERE printf("We are in %s", __func__)
    WHERE;
    }


    --
    Guillaume Dargaud
    http://www.gdargaud.net/
    "What is it about a man's cell phone going off in a theater that makes him
    look more and more like Abe Lincoln ? - Jerry L. Embry.
     
    Guillaume Dargaud, Dec 5, 2007
    #1
    1. Advertising

  2. Guillaume Dargaud

    Guest

    On Dec 5, 1:29 pm, "Guillaume Dargaud"
    <> wrote:
    > Hello all,
    > Is it the same thing to do those two things:
    >
    > #define WHERE printf("We are in %s", __func__)
    > void Function(void) {
    > WHERE;
    >
    > }
    >
    > And this:
    >
    > void Function(void) {
    > #define WHERE printf("We are in %s", __func__)
    > WHERE;
    >
    > }


    There's no __func__ in C99.
     
    , Dec 5, 2007
    #2
    1. Advertising

  3. schrieb:
    > On Dec 5, 1:29 pm, "Guillaume Dargaud"
    > <> wrote:


    >> #define WHERE printf("We are in %s", __func__)
    >> void Function(void) {
    >> WHERE;
    >>
    >> }
    >>
    >> And this:
    >>
    >> void Function(void) {
    >> #define WHERE printf("We are in %s", __func__)
    >> WHERE;
    >>
    >> }


    Yes. Both expands to:

    void Function(void) {
    printf("We are in %s", __func__);

    }

    > There's no __func__ in C99.


    There is.

    6.4.2.2 #1 says:

    The identifier __func__ shall be implicitly declared by the translator
    as if, immediately following the opening brace of each function
    definition, the declaration

    static const char __func__[] = "function-name";

    appeared, where function-name is the name of the lexically- enclosing
    function.

    --
    OMG,-10==10 in linux!
     
    Björn Paetzel, Dec 5, 2007
    #3
  4. In article <fj621u$a9s$2p3.fr>,
    Guillaume Dargaud <> wrote:

    >Is it the same thing to do those two things:
    >
    >#define WHERE printf("We are in %s", __func__)
    >void Function(void) {
    > WHERE;
    >}
    >
    >And this:
    >
    >void Function(void) {
    > #define WHERE printf("We are in %s", __func__)
    > WHERE;
    >}


    Yes, because __func__ is required to be like a variable, rather than
    a preprocessor macro.

    -- Richard

    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Dec 5, 2007
    #4
  5. Guillaume Dargaud

    santosh Guest

    wrote:

    > On Dec 5, 1:29 pm, "Guillaume Dargaud"
    > <> wrote:
    >> Hello all,
    >> Is it the same thing to do those two things:
    >>
    >> #define WHERE printf("We are in %s", __func__)
    >> void Function(void) {
    >> WHERE;
    >>
    >> }
    >>
    >> And this:
    >>
    >> void Function(void) {
    >> #define WHERE printf("We are in %s", __func__)
    >> WHERE;
    >>
    >> }

    >
    > There's no __func__ in C99.


    C & V please.
     
    santosh, Dec 5, 2007
    #5
  6. Guillaume Dargaud

    Jalapeno Guest

    On Dec 5, 8:43 am, santosh <> wrote:
    > wrote:
    > > On Dec 5, 1:29 pm, "Guillaume Dargaud"
    > > <> wrote:
    > >> Hello all,
    > >> Is it the same thing to do those two things:

    >
    > >> #define WHERE printf("We are in %s", __func__)
    > >> void Function(void) {
    > >> WHERE;

    >
    > >> }

    >
    > >> And this:

    >
    > >> void Function(void) {
    > >> #define WHERE printf("We are in %s", __func__)
    > >> WHERE;

    >
    > >> }

    >
    > > There's no __func__ in C99.

    >
    > C & V please.- Hide quoted text -
    >


    Why it's right here:

    http://www.youtube.com/watch?v=6lj9_zBobJs
     
    Jalapeno, Dec 5, 2007
    #6
  7. Guillaume Dargaud

    Guest

    On Dec 5, 3:43 pm, santosh <> wrote:
    > wrote:
    > > On Dec 5, 1:29 pm, "Guillaume Dargaud"
    > > <> wrote:
    > >> Hello all,
    > >> Is it the same thing to do those two things:

    >
    > >> #define WHERE printf("We are in %s", __func__)
    > >> void Function(void) {
    > >> WHERE;

    >
    > >> }

    >
    > >> And this:

    >
    > >> void Function(void) {
    > >> #define WHERE printf("We are in %s", __func__)
    > >> WHERE;

    >
    > >> }

    >
    > > There's no __func__ in C99.

    >
    > C & V please.


    I answered from memory.
    Can't always be right on usenet :)
     
    , Dec 5, 2007
    #7
  8. Guillaume Dargaud

    Neil Booth Guest

    Richard Tobin wrote:
    > In article <fj621u$a9s$2p3.fr>,
    > Guillaume Dargaud <> wrote:
    >
    >> Is it the same thing to do those two things:
    >>
    >> #define WHERE printf("We are in %s", __func__)
    >> void Function(void) {
    >> WHERE;
    >> }
    >>
    >> And this:
    >>
    >> void Function(void) {
    >> #define WHERE printf("We are in %s", __func__)
    >> WHERE;
    >> }

    >
    > Yes, because __func__ is required to be like a variable, rather than
    > a preprocessor macro.


    Not "because": even if it were a macro the answer would still be yes.

    Neil.
     
    Neil Booth, Dec 5, 2007
    #8
  9. In article <4756bd29$0$287$-net.or.jp>,
    Neil Booth <dev@null> wrote:

    >>> Is it the same thing to do those two things:
    >>>
    >>> #define WHERE printf("We are in %s", __func__)
    >>> void Function(void) {
    >>> WHERE;
    >>> }
    >>>
    >>> And this:
    >>>
    >>> void Function(void) {
    >>> #define WHERE printf("We are in %s", __func__)
    >>> WHERE;
    >>> }


    >> Yes, because __func__ is required to be like a variable, rather than
    >> a preprocessor macro.


    >Not "because": even if it were a macro the answer would still be yes.


    Um yes. I should have said "... rather than some magic thing that
    gets replaced when it is first encountered in the text".

    -- Richard

    --
    :wq
     
    Richard Tobin, Dec 5, 2007
    #9
  10. >>Not "because": even if it were a macro the answer would still be yes.

    > Um yes. I should have said "... rather than some magic thing that
    > gets replaced when it is first encountered in the text".


    Thanks, that sums it up nicely.
    --
    Guillaume Dargaud
    http://www.gdargaud.net/
     
    Guillaume Dargaud, Dec 5, 2007
    #10
  11. Guillaume Dargaud

    Tor Rustad Guest

    wrote:
    >
    > There's no __func__ in C99.


    Just for the record, there is a __func__ in C99, ref. 6.4.2.2.

    --
    Tor < | tr i-za-h a-z>
     
    Tor Rustad, Dec 9, 2007
    #11
    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,327
    Samuele Armondi
    Oct 30, 2003
  2. djinni

    curiosity question regarding __func__

    djinni, Aug 12, 2003, in forum: C Programming
    Replies:
    2
    Views:
    331
    Ajey B Kulkarni
    Aug 13, 2003
  3. Replies:
    3
    Views:
    3,682
    Chris Torek
    Feb 20, 2006
  4. Replies:
    9
    Views:
    4,857
    Ancient_Hacker
    Oct 26, 2006
  5. none

    The variable __func__ in C89 in gcc

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

Share This Page