home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!usenet.coe.montana.edu!saimiri.primate.wisc.edu!ames!kronos.arc.nasa.gov!joshr
- From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: &StringPtr -vs- StringPtr?
- Message-ID: <1993Jan25.211652.28191@kronos.arc.nasa.gov>
- Date: 25 Jan 93 21:16:52 GMT
- Article-I.D.: kronos.1993Jan25.211652.28191
- References: <1993Jan22.165348.11313@novell.com> <1993Jan22.200837.13294@kronos.arc.nasa.gov> <1993Jan22.220940.21096@hobbes.kzoo.edu>
- Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
- Organization: NASA/ARC Information Sciences Division
- Lines: 60
- Nntp-Posting-Host: mcc2.arc.nasa.gov
-
- In article <1993Jan22.220940.21096@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
- >joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91) writes:
- >>damurphy@wc.novell.com (Duane Murphy) writes:
- >>>
- >>>I have received some code... The MPW compiler says nothing, but
- >>>Think C whines about types not matching. Here is where the problem is:
- >>>
- >>> Str255 msg1, msg2;
- >>> GetIndString(&msg1, errResID, errStringIndex);
- >>>
- >>>The problem is &msg1. The prototype for GetIndString is:
- >>>(from ToolUtils.h)
- >>>
-
- ((( josh had suggested casting it with ConstStr255Param. ))), and said:
- >>msg1 is the address of the first element, and &msg1 has no real
- >>meaning (thoug usually is interpreted as just &msg1[0], or msg1).
- >
- >Well, "&msg1" does have a well-defined meaning. The expression "msg1"
- >does have the type "pointer to unsigned char," and is equivalent to
- >the more-logical-looking "&msg1[0]". But "&msg1", while it points to
- >the same place, has the type "pointer to array of 256 unsigned chars."
- >That's not the same thing.
-
- I stand corrected.
- >
-
- >To quote gospel at you: "If the type of an expression or subexpression
- >is 'array of T,' for some type T, then the value of the expression is a
- >pointer to the first object in the array, and the type of the expression
- >is altered to 'pointer to T.' This conversion does not take place if
- >the expression is the operand of the unary & operator, or of ++, --,
- >sizeof, or as the left operand of an assignment operator or the .
- >operator." (K&R, 2nd ed., A7.1, p. 200.) So, "msg1" by itself is a
- >pointer to unsigned char; "&msg1" is a pointer to an array of 256
- >unsigned chars; "sizeof(msg1)" returns the size of the array instead of
- >the size of a pointer; "++msg1" increments the pointer 256 bytes
- >instead of one, and so on. Ain't C grand?
- >
- >>I would say that if you passed msg1 (not &msg1), it SHOULD accept it.
- >>I believe I usually must cast in that situation as well, though.
- >I don't think so. At least, I don't have to, and I keep ThC on its
- >strictest type-checking.
-
-
- Hmmm. Did you recompile MacHeaders with the strcit prototype #define
- chosen? I think the (ConstStr255Param) need only cropped up after
- I made that change.`
-
- Interesting, that bit about sizeof(msg). What happens at sizeof(&msg) ( ;-) )?
-
- >--
- > Jamie McCarthy Internet: k044477@kzoo.edu AppleLink: j.mccarthy
-
-
- --
- ----------------------------------
- #include <std/disclaimer.h> Josh Rabinowitz, Mac TCL programmer
- joshr@kronos.arc.nasa.gov
- "Me lost my cookie at the disco." -- Cookie Monster
-