What's the lifetime of __FILE__?

D

DeMarcus

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
 
J

Jerry Coffin

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).
 
D

DeMarcus

Jerry said:
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!
 
D

DeMarcus

Geoff said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top