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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!gumby!wupost!csus.edu!netcom.com!jimlynch
  3. From: jimlynch@netcom.com (Jim Lynch)
  4. Subject: initialized 'global' (extern) char arrays
  5. Message-ID: <1993Jan7.032458.21941@netcom.com>
  6. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  7. Date: Thu, 7 Jan 1993 03:24:58 GMT
  8. Lines: 41
  9.  
  10. I am given to understand that the storage allocated by
  11.  
  12. char *x = "abcde" ;
  13.  
  14. is not writable. In terms of whatever standard exists, is it exactly the same as
  15.  
  16. const char *x = "abcde" ;  // ?
  17.  
  18. The reason I ask is that I used such a construct in gcc-2.3.2 (yes, I plan to
  19. upgrade) as follows:
  20.  
  21. char *x = "some string" ;
  22.  
  23. main()
  24. {
  25.     something(x[0]) ;
  26. }
  27.  
  28. where the prototype for something looks like
  29.  
  30. void something(char &z) ;
  31.  
  32. and modifies that which is referred to by z.
  33.  
  34. So when something() got around to modifying, the system dumped core, claiming
  35. a segmentation fault. Shouldn't the compiler have warned me?
  36.  
  37. Also, some internal issues:
  38.  
  39. Assuming that x is a const char *, does the C compiler see the argument to
  40. something() in main() as needing a type conversion from const char to plain
  41. ol' char? If so, shouldn't the compiler warn about this (possibly probematic)
  42. kind of conversion?
  43.  
  44. Someone told me that even though the ANSI standard says that x is unwritable,
  45. the compiler won't implement this by making it a const. My feeling is that this
  46. is a mistake: unwritable should imply const (although my assumption was the
  47. other way around: unwritable is implemented through using const.)
  48.  
  49. -Jim
  50.  
  51.