home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12761 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.5 KB  |  41 lines

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