Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: double strtod( const char *nPtr, char **endPrt); Date: Thu, 12 Nov 2015 12:48:07 -0800 Organization: None to speak of Lines: 48 Message-ID: References: <6b8eee47-6184-45f2-8b56-b0e51c16a763@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="9853"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bo9C8+Cz38vHA1qQF5jAc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:US2uPeEXETh32MVTVBXKqZKL1d4= sha1:tEVssMnoFRw3ybsurS1trGST5+Q= Xref: csiph.com comp.lang.c:75877 supercat@casperkitty.com writes: > On Thursday, November 12, 2015 at 1:33:08 PM UTC-6, Keith Thompson wrote: >> A string literal, unlike a character or integer constant, does cause the >> creation of an object at run time. A char* pointer *can* point to an >> element of that object. (And for safety, such a pointer should be >> declared as "const char*", because you want to avoid trying to modify >> the contents of the array created by the string literal.) > > While I don't think anything would forbid an implementation where string > literals could create objects at run time, I would suggest that they more > often create objects at compile time which are aggregated into an object > which gets created at load time. String literal expressions then identify > pieces of that object. Objects don't exist at compile time. A compiler doesn't create an object. It generates code that results in the creation of an object when that code is executed. When a C compiler encounters a string literal, it generates code that, when executed, will result in the runtime creation of an array object that will hold the specified sequence of values. That creation logically occurs some time after the program starts executing but before entry to main(). Typically it might occur as the operating system is loading the executable (so there might not actually be a sequence of CPU instructions in the executable that causes the object to be created), and the object might be bundled with other static objects, but those are implementation details. All this is subject to optimization; an object that's never referenced might not be created. So, in my source code I have: const char *s = "hello"; At run time, there exists a static object of type char[6] containing the characters { 'h', 'e', 'l', 'l', 'o', '\0' }. After the flow of execution reaches the declaratio nof s, it is initialized to point to the element containing the 'h'. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"