home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Simple C question
- Message-ID: <1992Aug25.163934.5416@taumet.com>
- Organization: TauMetric Corporation
- References: <6966270d@lynx.unm.edu> <760a5705@p3.f6.n249.z2.fidonet.org> <1992Aug24.200847.14366@cs.brown.edu>
- Date: Tue, 25 Aug 1992 16:39:34 GMT
- Lines: 30
-
- sj@cs.brown.edu (Shuang Ji) writes:
-
- >In article <760a5705@p3.f6.n249.z2.fidonet.org>, Gilles_Kohl@spam.fido.de (Gilles Kohl) writes:
- >|> > main()
- >|>
- >|> > {
- >|> > char s[] = "Hello world!" ;
- >|> > }
-
- >Variables declared as "char s[]" are not considered to be left values. And in fact,
- >the value of the string "Hello world" is the address of this staticly stored
- >string. So this initialization is illegal.
-
- No, it is legal (but see below). There is a special dispensation for
- literal strings used to initialize arrays of char. For this purpose
- only, "hello" is considered a shorthand for {'h','e','l','l','o','\0'}.
- Thus, both of these are legal, but mean different things:
- char *p = "hello";
- char s[] = "hello";
- The first initializes 'p' to point to an anonymous array of chars
- containing "hello" (plus a null), and the second defines 's' to be an
- array of 6 chars containing "hello" (plus a null).
-
- Pre-Standard compilers typically did not allow initialization of
- aggregate auto variables, but only those of with static storage duration.
- A Standard compiler allows initialization of auto aggregates, as above.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-