home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22159 < prev    next >
Encoding:
Text File  |  1993-01-25  |  3.2 KB  |  74 lines

  1. Path: sparky!uunet!ogicse!usenet.coe.montana.edu!saimiri.primate.wisc.edu!ames!kronos.arc.nasa.gov!joshr
  2. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: &StringPtr -vs- StringPtr?
  5. Message-ID: <1993Jan25.211652.28191@kronos.arc.nasa.gov>
  6. Date: 25 Jan 93 21:16:52 GMT
  7. Article-I.D.: kronos.1993Jan25.211652.28191
  8. References: <1993Jan22.165348.11313@novell.com> <1993Jan22.200837.13294@kronos.arc.nasa.gov> <1993Jan22.220940.21096@hobbes.kzoo.edu>
  9. Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
  10. Organization: NASA/ARC Information Sciences Division
  11. Lines: 60
  12. Nntp-Posting-Host: mcc2.arc.nasa.gov
  13.  
  14. In article <1993Jan22.220940.21096@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  15. >joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91) writes:
  16. >>damurphy@wc.novell.com (Duane Murphy) writes:
  17. >>>
  18. >>>I have received some code...  The MPW compiler says nothing, but
  19. >>>Think C whines about types not matching.  Here is where the problem is:
  20. >>>
  21. >>>    Str255    msg1, msg2;
  22. >>>    GetIndString(&msg1, errResID, errStringIndex);
  23. >>>
  24. >>>The problem is &msg1.  The prototype for GetIndString is:
  25. >>>(from ToolUtils.h)
  26. >>>
  27.  
  28. ((( josh had suggested casting it with ConstStr255Param. ))), and said:
  29. >>msg1 is the address of the first element, and &msg1 has no real
  30. >>meaning (thoug usually is interpreted as just &msg1[0], or msg1).
  31. >
  32. >Well, "&msg1" does have a well-defined meaning.  The expression "msg1"
  33. >does have the type "pointer to unsigned char," and is equivalent to
  34. >the more-logical-looking "&msg1[0]".  But "&msg1", while it points to
  35. >the same place, has the type "pointer to array of 256 unsigned chars."
  36. >That's not the same thing.
  37.  
  38. I stand corrected.
  39. >
  40.  
  41. >To quote gospel at you:  "If the type of an expression or subexpression
  42. >is 'array of T,' for some type T, then the value of the expression is a
  43. >pointer to the first object in the array, and the type of the expression
  44. >is altered to 'pointer to T.'  This conversion does not take place if
  45. >the expression is the operand of the unary & operator, or of ++, --,
  46. >sizeof, or as the left operand of an assignment operator or the .
  47. >operator."  (K&R, 2nd ed., A7.1, p. 200.)  So, "msg1" by itself is a
  48. >pointer to unsigned char;  "&msg1" is a pointer to an array of 256
  49. >unsigned chars;  "sizeof(msg1)" returns the size of the array instead of
  50. >the size of a pointer;  "++msg1" increments the pointer 256 bytes
  51. >instead of one, and so on.  Ain't C grand?
  52. >
  53. >>I would say that if you passed msg1 (not &msg1), it SHOULD accept it.
  54. >>I believe I usually must cast in that situation as well, though.
  55. >I don't think so.  At least, I don't have to, and I keep ThC on its
  56. >strictest type-checking.
  57.  
  58.  
  59. Hmmm.  Did you recompile MacHeaders with the strcit prototype #define
  60. chosen?  I think the (ConstStr255Param) need only cropped up after
  61. I made that change.`
  62.  
  63. Interesting, that bit about sizeof(msg).  What happens at  sizeof(&msg) ( ;-) )?
  64.  
  65. >-- 
  66. > Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  67.  
  68.  
  69. -- 
  70. ----------------------------------
  71. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  72. joshr@kronos.arc.nasa.gov
  73. "Me lost my cookie at the disco." -- Cookie Monster
  74.