home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 1999 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.5 KB  |  44 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: initialized 'global' (extern) char arrays
  5. Message-ID: <9300812.4657@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1993Jan7.032458.21941@netcom.com>
  9. Date: Fri, 8 Jan 1993 01:23:49 GMT
  10. Lines: 32
  11.  
  12. jimlynch@netcom.com (Jim Lynch) writes:
  13.  
  14. >I am given to understand that the storage allocated by
  15. >
  16. >char *x = "abcde" ;
  17. >
  18. >is not writable.
  19.  
  20. Correct.
  21.  
  22. >The reason I ask is that I used such a construct in gcc-2.3.2 ...
  23. [example omitted]
  24. >... Shouldn't the compiler have warned me?
  25.  
  26. With gcc, use the -Wwrite-strings option. Here's an extract from the
  27. manual:
  28.  
  29.       -Wwrite-strings
  30.            Give string constants the type  const  char[length]  so
  31.            that copying the    address    of one into a non-const    char *
  32.            pointer will get    a warning.  These warnings  will  help
  33.            you  find  at  compile  time code that can try to write
  34.            into a string constant, but only    if you have been  very
  35.            careful    about  using  const in declarations and    proto-
  36.            types.  Otherwise, it will just be a nuisance; this  is
  37.            why we did not make `-Wall' request these warnings.
  38.  
  39. -- 
  40. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  41. This .signature virus is a self-referential statement that is true - but 
  42. you will only be able to consistently believe it if you copy it to your own
  43. .signature file!
  44.