Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #75877

Re: double strtod( const char *nPtr, char **endPrt);

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
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 <lny4e3osfs.fsf@kst-u.example.com> (permalink)
References <fcf0991b-eb10-4594-8745-0ae2fc15721f@googlegroups.com> <lnk2pnqiwk.fsf@kst-u.example.com> <6b8eee47-6184-45f2-8b56-b0e51c16a763@googlegroups.com> <ln7flnqahi.fsf@kst-u.example.com> <c866d654-7f88-4036-812a-097405478809@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

Show key headers only | View raw


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  <http://www.ghoti.net/~kst>
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"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

double strtod( const char *nPtr, char **endPrt); G G <gdotone@gmail.com> - 2015-11-11 22:55 -0800
  Re: double strtod( const char *nPtr, char **endPrt); Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 07:24 +0000
    Re: double strtod( const char *nPtr, char **endPrt); G G <gdotone@gmail.com> - 2015-11-11 23:42 -0800
  Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 08:31 -0800
    Re: double strtod( const char *nPtr, char **endPrt); supercat@casperkitty.com - 2015-11-12 08:52 -0800
    Re: double strtod( const char *nPtr, char **endPrt); G G <gdotone@gmail.com> - 2015-11-12 09:43 -0800
      Re: double strtod( const char *nPtr, char **endPrt); Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 17:59 +0000
      Re: double strtod( const char *nPtr, char **endPrt); Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-12 13:10 -0500
      Re: double strtod( const char *nPtr, char **endPrt); James Kuyper <jameskuyper@verizon.net> - 2015-11-12 13:19 -0500
      Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 11:32 -0800
        Re: double strtod( const char *nPtr, char **endPrt); supercat@casperkitty.com - 2015-11-12 12:17 -0800
          Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 12:48 -0800
            Re: double strtod( const char *nPtr, char **endPrt); supercat@casperkitty.com - 2015-11-12 13:39 -0800
              Re: double strtod( const char *nPtr, char **endPrt); glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-12 23:24 +0000
              Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 17:14 -0800
                Re: double strtod( const char *nPtr, char **endPrt); supercat@casperkitty.com - 2015-11-12 17:42 -0800
                Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 18:20 -0800
            Re: double strtod( const char *nPtr, char **endPrt); glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-12 23:15 +0000
              Re: double strtod( const char *nPtr, char **endPrt); Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-12 18:30 -0500
                Re: double strtod( const char *nPtr, char **endPrt); supercat@casperkitty.com - 2015-11-12 16:47 -0800
                Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 18:07 -0800
                Re: double strtod( const char *nPtr, char **endPrt); glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-13 02:41 +0000
                Re: double strtod( const char *nPtr, char **endPrt); glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-13 02:53 +0000
        Re: double strtod( const char *nPtr, char **endPrt); G G <gdotone@gmail.com> - 2015-11-12 12:17 -0800
  Re: double strtod( const char *nPtr, char **endPrt); Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-12 12:34 -0800
    Re: double strtod( const char *nPtr, char **endPrt); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-12 23:54 +0000
      Re: double strtod( const char *nPtr, char **endPrt); Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-12 16:23 -0800
        Re: double strtod( const char *nPtr, char **endPrt); Ian Collins <ian-news@hotmail.com> - 2015-11-13 14:09 +1300
          Re: double strtod( const char *nPtr, char **endPrt); Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-12 17:31 -0800
            Re: double strtod( const char *nPtr, char **endPrt); Ian Collins <ian-news@hotmail.com> - 2015-11-13 14:46 +1300
        Re: double strtod( const char *nPtr, char **endPrt); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-13 02:07 +0000
        Re: double strtod( const char *nPtr, char **endPrt); David Brown <david.brown@hesbynett.no> - 2015-11-13 08:48 +0100
    Re: double strtod( const char *nPtr, char **endPrt); Keith Thompson <kst-u@mib.org> - 2015-11-12 16:57 -0800

csiph-web