Thanks to everyone who explained to me why the second StrPrintF didn't work
(passing ints when it wants longs), but the third was the real problem...

If I tell StrPrintF to parse my 'unsigned long' as a 'unsigned long' it will
still parse it as it was a 'signed long'.


Here's the example code:

  ULong test;
  
  charP = MemPtrNew(1024);

  test = 0x7FFFFFFF;   // Very close to wrap around for _SIGNED_ longs.
  StrPrintF(charP, "%lu", test);
  test += 10;   // If test was _SIGNED_ it would be negative now.
  StrPrintF(charP, "%lu", test);
  StrPrintF(charP, "%lu", (ULong)test); // To be 100% sure.
          
And here's the value of 'test' and 'charP' after each row...

  test = 0x7FFFFFFF;   // Very close to wrap around for _SIGNED_ longs.
    charP = 0x1a614 "<unitialized>"
    test = 2147483647
  StrPrintF(charP, "%lu", test);
    charP = 0x1a614 "2147483647"
    test = 2147483647
  test += 10;   // If test was _SIGNED_ it would be negative now.
    charP = 0x1a614 "2147483647"
    test = 2147483657
       (Checking to cast test to (long) just to check if it was negative)
       print (long)test
         $1 = -2147483639
  StrPrintF(charP, "%lu", test);
    charP = 0x1a614 "-2147483639"
    test = 2147483657
  StrPrintF(charP, "%lu", (ULong)test); // To be 100% sure.
    charP = 0x1a614 "-2147483639"
    test = 2147483657



Have noone else seen this? Does this only happen on my system? I'm running
this in PalmOS Emulator 3.0a4 with the v3.1 ROM downloaded from a PalmV,
Program compiled with 'egcs-2.91.57-kgpd' (according to --version) and the
sdk3. (I know these things are not the latest versions, but I haven't had
time to update them, it takes a day or two. ;) )

A confirmation from anyone else having this problem would be nice. :)

Palm knowledgebase is down (as usual) so I can't check it it's known.

//Fredde


On Thu, May 04, 2000 at 10:01:09AM -0700, Fitzpatrick, Joe wrote:
> In the second use of StrPrintF your format string is telling the
> StrPrintF function to expect 4 byte values on the stack, but you are
> still just pushing 2 byte values onto the stack.  If you cast the two
> literals to 'unsigned long' (or the appropriate Palm data type) your
> second case will give the results you expect.
> 
> I'm not sure what is up with your third example, but I suspect that it
> is a similar problem (mismatch between the argument sizes expected and
> the actual arguments passed).
> 
> Good luck,
> -jjf
> 



>>    StrPrintF(charP, "%lu %lu", uniqueId, temp);
>> with (uniqueId is TimGetSeconds()):
>>    print uniqueId
>>       $1 = 3040295183
>>    ptype uniqueId
>>       type = unsigned long
>>    charP = 0x1a614 "-1254672113 3855"
>> 

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to