home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16583 < prev    next >
Encoding:
Internet Message Format  |  1992-11-16  |  1.5 KB

  1. Path: sparky!uunet!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: const char *p == char const *p ?
  5. Message-ID: <3870@dozo.and.nl>
  6. Date: 16 Nov 92 10:32:00 GMT
  7. References: <1992Nov15.162912.17454@news.uiowa.edu> <1992Nov16.010820.26757@cs.tu-berlin.de>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 30
  10.  
  11. In article <1992Nov16.010820.26757@cs.tu-berlin.de> jutta@opal.cs.tu-berlin.de (Jutta Degener) writes:
  12. |bonak@herky.cs.uiowa.edu (Esmail Bonakdarian) writes:
  13. |> Is "char const *p" equivalent to "const char *p"?
  14. |
  15. |Yes.  They are both pointers to constant character; you may
  16. |change the pointer, but not the character it points to.
  17. |
  18. |Some programmers prefer "char const *" to "const char *".
  19. |They argue that C declarations are read "inside out":
  20. |
  21. |   char const * p ;
  22. |                ^     p is a
  23. |              ^              pointer to
  24. |        ^^^^^                           constant
  25. |   ^^^^                                          char
  26. |
  27. |But that's just a matter of style.
  28.  
  29. Sorry, you're making a mistake, `const char * p' is _not_ equivalent
  30. to `char * const p'. The first declaration reads: `there is a character
  31. constant, and p points to it', while the second one reads: `this is 
  32. a character pointer p and it is a constant.' 
  33.  
  34. Using `char * const p' without an explicit initialization is quite
  35. silly, because assigning a value to p later on in the code, is
  36. not allowed. I do agree that the syntax is a bit confusing ...
  37.  
  38. kind regards,
  39.  
  40. Jos aka jos@and.nl
  41.