On Thu, Oct 03, 2002 at 05:43:38AM -0500, Michael Harrison wrote:
> TraceOutput( TL( appErrorClass, "re-allocated %hu bytes of record
> memory", gNumRecordsAllocated * sizeof(UInt16) ) );

The sizeof operator returns a size_t, which, on Palm OS with both GCC
and CodeWarrior, is the same size as a long.  So your code is wrong: you
should be using %lu instead.

Rather than trying to remember how big a size_t is, when passing one
to a varargs function like printf it's a common idiom to cast it to
something known, as you have done:

> TraceOutput( TL( appErrorClass, "re-allocated %hu bytes of record
> memory", UInt16(gNumRecordsAllocated * sizeof(UInt16)) ) );

or to use an explicit temporary:

> UInt16 BytesAlloc = gNumRecordsAllocated * sizeof(UInt16);
> TraceOutput( TL( appErrorClass, "re-allocated %hu bytes of record
> memory", BytesAlloc ) );

Both of these produced the appropriately sized argument for %hu for me.
I was unable to reproduce the problem you say you had with the former.

    John

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

Reply via email to