473,513 Members | 11,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Life time of the string referenced by a __FILE__ preprocessor statement.

This is somewhat obscure, and I'm not sure if the question is valid in
comp.lang.c. If it isn't, please ignore it.

In a C program, the pointer resulting from a __FILE__ is stored.
The pointer refers to a normal string constant (I think).
Does the standard say anything about when that constant is destroyed,
thus rendering any use of the stored pointer undefined behavior?

I guess the question might be simplified into:

"What's the lifetime of a string constant?"

My gut reaction is of course "Until the program ends".

Regards,

Johan
Nov 14 '05 #1
1 1768
Johan Lindh wrote:
In a C program, the pointer resulting from a __FILE__ is stored.
The pointer refers to a normal string constant (I think).
I'm not quite sure what you mean. __FILE__ is textually replaced with
a string literal (i.e. an anonymous null-terminated array of char).
I guess the question might be simplified into:

"What's the lifetime of a string constant?"

My gut reaction is of course "Until the program ends".


Right. A string literal object has "static" storage duration, which
means:

Its lifetime is the entire execution of the program and its stored
value is initialized only once, prior to program startup.
[C99 6.2.4]

Jeremy.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

97
27692
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
18
11323
by: Paul Shipley | last post by:
Hi, Does anyone know a way of converting the __LINE__ macro to a string at compile time? The reason I ask it because I want to put some debug information in to tell me if memory is not being...
3
4494
by: Ilja Booij | last post by:
Hi all, I have some trouble with the following: I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM, where the...
5
2686
by: baumann.Pan | last post by:
where are these macros defined? can I use it a release ver code?
11
387
by: babuyama | last post by:
Hi, Is there a way to obtain library name at compile/preprocessor time? Assuming that the compilation unit, myfile.c is part of mylib.a, from myfile.c code at compile/preprocessor time, I would...
0
2005
by: Krishnan | last post by:
Hi I am trying to build a small client-server program using OpenSSL functions. I get errors on trying to build the program using Visual Studio .Net (Visual C++ 7.0). I am new to Visual Studio...
18
29252
by: Lukas Ruf | last post by:
Dear all, for debugging purposes, I like the pre-compiler macros __FILE__, __FUNCTION__, __LINE__ I have been wondering if there is a short form of __FILE__ that provides only the filename...
7
2733
by: Plissken.s | last post by:
Hi, If I define a template wich uses the __FILE__ marco in a .h file and I have class which creates/uses that template (in a .cpp file). What will the __FILE__ marco expand to? the .h which...
8
2681
by: xmllmx | last post by:
It seems true, but I can't find any exact statement on this in the C or C++ standard. The C and C++ standard states: "__FILE_ The presumed name of the source file (a character string...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.