What's the lifetime of __FILE__?

Discussion in 'C++' started by DeMarcus, May 11, 2010.

  1. DeMarcus

    DeMarcus Guest

    Hi,

    What's the lifetime of the __FILE__ pointer? Until the end of the scope
    where it's used?

    The same with __func__. What's the lifetime of that pointer?

    Thanks,
    Daniel
     
    DeMarcus, May 11, 2010
    #1
    1. Advertising

  2. DeMarcus

    Jerry Coffin Guest

    In article <4be8f85c$0$282$>,
    says...
    >
    > Hi,
    >
    > What's the lifetime of the __FILE__ pointer? Until the end of the scope
    > where it's used?
    >
    > The same with __func__. What's the lifetime of that pointer?


    Both __FILE__ and __func__ yield addresses of string literals.
    They're basically rvalues (i.e., just values) that don't really have
    lifetimes as such. They point at string literals which have static
    storage duration. You can assign the values to pointers that have
    whatever lifetime you prefer (static, automatic, whatever).

    --
    Later,
    Jerry.
     
    Jerry Coffin, May 11, 2010
    #2
    1. Advertising

  3. DeMarcus

    DeMarcus Guest

    Jerry Coffin wrote:
    > In article <4be8f85c$0$282$>,
    > says...
    >> Hi,
    >>
    >> What's the lifetime of the __FILE__ pointer? Until the end of the scope
    >> where it's used?
    >>
    >> The same with __func__. What's the lifetime of that pointer?

    >
    > Both __FILE__ and __func__ yield addresses of string literals.
    > They're basically rvalues (i.e., just values) that don't really have
    > lifetimes as such. They point at string literals which have static
    > storage duration. You can assign the values to pointers that have
    > whatever lifetime you prefer (static, automatic, whatever).
    >


    Thanks!
     
    DeMarcus, May 11, 2010
    #3
  4. DeMarcus

    DeMarcus Guest

    Geoff wrote:
    > On Tue, 11 May 2010 08:25:39 +0200, DeMarcus
    > <> wrote:
    >
    >> Hi,
    >>
    >> What's the lifetime of the __FILE__ pointer? Until the end of the scope
    >> where it's used?
    >>
    >> The same with __func__. What's the lifetime of that pointer?
    >>
    >> Thanks,
    >> Daniel

    >
    > What does your compiler documentation say?
    >


    I use g++ and it seems to conform to C++0x.
    http://gcc.gnu.org/projects/cxx0x.html

    > __FILE__ has file scope. It's lifetime is the current translation
    > unit. It's usually implemented as a preprocessor macro.
    >
    > __func__ is the name of the current function in the TU, it has
    > function scope. The function-local predefined variable __func__ is
    > defined as if a definition of the form
    >
    > static const char __func__[] = "function-name ";
    >
    > had been provided at the opening brace of the function.


    Ok, great! So I can use the pointer throughout the application without
    the need to copy its string.
     
    DeMarcus, May 11, 2010
    #4
    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. Spry
    Replies:
    1
    Views:
    949
    Richard Heathfield
    Jul 26, 2003
  2. qazmlp

    Definition of __FILE__, __LINE__

    qazmlp, Aug 9, 2003, in forum: C Programming
    Replies:
    9
    Views:
    617
    Mark McIntyre
    Aug 19, 2003
  3. Johan Lindh
    Replies:
    1
    Views:
    334
    Jeremy Yallop
    May 5, 2004
  4. Darren Dale

    Proper use of __file__

    Darren Dale, Oct 5, 2004, in forum: Python
    Replies:
    3
    Views:
    45,455
    David Bolen
    Oct 5, 2004
  5. klenwell

    __file__ vs __FILE__

    klenwell, Nov 3, 2007, in forum: Python
    Replies:
    11
    Views:
    928
    Matimus
    Nov 5, 2007
Loading...

Share This Page