At 03:36 PM 6/1/99 -0500, you wrote:
>I am trying to use this function to convert a number to a string to show
>up in a label.  i am doing something like this:
>
>....
>Long value;
>CharPtr s, c;
>       
>s=StrIToA(c, value);
>....
>
>
>whenever i have this line in my code, POSE crashes with a 'bus error'.
>this happens whether i use s or c or not.  if i comment out this line
>then no problems.  anyone know what is wrong with this?  also, why does
>it return a CharPtr and also set another CharPtr (returns s and sets
>c)?  which variable holds the string version of value?  why isnt it
>defined like CharPtr StrIToA(Long i) ?

You're meant to declare space for the result, ie

CharPtr s = MemPtrNew(10);
StrIToA(s, value);

The CharPtr returned is simply the address of the string, ie it returns s.

This flexibility is, I guess, to allow you to use it in a variety of
situations - eg when you need the return value, eg for use with StrPrintF
(... %s ...) or when you just want the effect, as in the code above.

It would be far messier if you passed an unintialised pointer and the
StrIToA call had to allocate space - what would it do if it ran out of
memory etc?

Paul.

Reply via email to