[comp.sys.mac] LSC printf

rs4u+@ANDREW.CMU.EDU (Richard Siegel) (09/10/87)

I haven't tried the code yet (I will, though) but what immediately strikes me is that
you don't lock the STR resource before you
call printf(). Since printf() calls an assortment of routines
that are in the class of "routines that may move or purge memory",
it's likely that your string is moving away on you.

Try this bit of code and see what happens:
#include <stdio.h>
#include <MacTypes.h>
#include <strings.h>
#include <pascal.h>
#define StringID 30292

main()                   /* This code works as written. */
        {
        char **myText;

        myText = (char **)GetString(StringID);
	HLock((Handle)(myText));
	        PtoCstr(*myText);
/* sorry about that indent ^^ */
	printf("%s\n", *myText);
	ExitToShell();
	}

As I said, I'll try the code and if I come across anything else I'll post.

		--Rich

****NOTE: The opinions (if any) herein are my own opinions and are
in no way representative of my employer's policies.

Richard M. Siegel
Customer Support Representative
THINK Technologies, Inc.

eacj@TCGOULD.TN.CORNELL.EDU (Julian Vrieslander) (09/11/87)

Thanks for the reply to my posting about the problem with printf.  It
looks like my friends and I forgot to consider the possibility that
printf could cause heap movement AFTER the text handle in its argument list
was dereferenced.

-Julian "feeling stupid" Vrieslander