[comp.sys.mac.programmer] strings again

MJSCHMEL@pucc.Princeton.EDU (Michael J. Schmelzer) (03/03/88)

Thank you everybody for the help in converting
C to Pascal strings. I had got it right, but was
a victim of my own prototyping. To wit:
 
pascal void Debugger()
	extern 0xA9FF;
 
pascal void DebugStr(aString)
	Str255 aString;
	extern 0xABFF;
	
static char *str = "Wowwy zowwy";
		
main()
{
	char buffer[255];
	
	Debugger(); /* works, no problem */
	
	strcpy(buffer, str);
	c2pstr(buffer);
	DebugStr(buffer); /* type mismatch here */
 
	printf("%s\nDone.\n",str); /* it's okay, it's an MPW tool */
}
 
Gave me a "Type mismatch." Why did it do that, I wondered.
Then I saw that I had prototyped it that way! (Which shouldn't
be faulted, because I got it verbatim from the MPW manual.)
 
Changing the prototype to...
pascal void DebugStr(aString)
	char * aString;
	extern 0xABFF;
...made it work like a charm. No problem.
 
Is there any way I could have made it work with the original
prototype? Simple typecasting -
	DebugStr ((Str255) buffer);
- did not work. (Why not?)
 
Yo Apple! How would I make the program work if it was
prototyped as a Str255??? Thanks everyone.
==============================================================================
comes around    Mike Schmelzer MJSCHMEL@PUCC.Princeton.Edu    what goes around
==============================================================================

MJSCHMEL@pucc.Princeton.EDU (Michael J. Schmelzer) (03/03/88)

Sorry, but in my last article, my tabs were replaced by semicolons.
I apologize to any who where confused by the mixup. Sorry!
==============================================================================
comes around    Mike Schmelzer MJSCHMEL@PUCC.Princeton.Edu    what goes around
==============================================================================

edmoy@violet.berkeley.edu (03/04/88)

In article <4629@pucc.Princeton.EDU> MJSCHMEL@pucc.Princeton.EDU writes:
>	. . .
>	DebugStr(buffer); /* type mismatch here */
> 
>	printf("%s\nDone.\n",str); /* it's okay, it's an MPW tool */
>}
> 
>Gave me a "Type mismatch." Why did it do that, I wondered.
>Then I saw that I had prototyped it that way! (Which shouldn't
>be faulted, because I got it verbatim from the MPW manual.)
>	. . .
> 
>Is there any way I could have made it work with the original
>prototype? Simple typecasting -
>	DebugStr ((Str255) buffer);
>- did not work. (Why not?)

I use LSC, but the problem is similar.  Pascal strings are (after hunting
down the type casting) unsigned chars.  So the following should work:

	DebugStr ((unsigned char *) buffer);

This is typedef'ed to StringPtr in some places so

	DebugStr ((StringPtr) buffer);

Str255 typedef is an array of unsigned chars, and you can't typedef with
arrays, only pointers in this case.

Edward Moy
Workstation Software Support Group
University of California
Berkeley, CA  94720

edmoy@violet.Berkeley.EDU
ucbvax!violet!edmoy