[Coco] Microware C Compiler port

William Astle lost at l-w.ca
Wed Jan 21 20:37:51 EST 2009


John W. Linville wrote:
> On Thu, Jan 22, 2009 at 10:47:38AM +1000, Bob Devries wrote:
>> Sent by private email, John.
> 
> Well, thanks -- that resolved the linking problem.  OTOH, the long
> variables still got printed as zeroes. :-(
> 
> John

Correct me if I'm wrong, but how does this theory work:

Assumption: long is twice as many bits as int and big-endian byte order,
both of which should be valid here.

Pretend we have a "long" value of 16. That would get onto the stack as
the following string of bytes: 00, 00, 00, 10.

Now printf() is looking for an integer so it only grabs 16 bits from the
stack which gets the bytes: 00 00

Magically, our "long" value turns into a 0.

The theory is that the format string being used is only cuing printf()
to look for an int value but a long int is on the stack.

I'm not overly familiar with the microware C compiler and the C library
involved but usually "%ld" is used for long ints rather than "%D", is it
not?

-- 
William Astle



More information about the Coco mailing list