EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

printf question

Started by Micah Stevens November 5, 2005
Hi,

I'm trying to output a signed int with printf() in crossworks so that I can

get some feedback in the debug window. 

It's working, but it's not displaying negative numbers properly,
it's giving 
the two's compliment instead, i.e. 65534 instead of -1.. 

Is there a format string switch that I can use to force it to be in signed 
mode? I looked on the net, and in the crossworks docs, and can't find 
anything. Maybe I'm totally missing something. 

Currently I'm just doing this: 
signed int x;
(code)
debug_printf("%d\n", x);

This may apply to other compilers as well, as I assume that cross studio's 
printf format strings are pretty standard.

Thanks for your help,
-Micah

Beginning Microcontrollers with the MSP430

Hi Micah, 

> I'm trying to output a signed int with
printf() in crossworks 
> so that I can get some feedback in the debug window. 
> 
> It's working, but it's not displaying negative numbers 
> properly, it's giving the two's compliment instead, i.e. 
> 65534 instead of -1.. 

This, I think, is a known problem.

> Is there a format string switch that I can use to
force it to 
> be in signed mode? I looked on the net, and in the crossworks 
> docs, and can't find anything. Maybe I'm totally missing
something. 
> 
> Currently I'm just doing this: 
> signed int x;
> (code)
> debug_printf("%d\n", x);

You could try:

debug_printf("%ld\n", (long)x);

> This may apply to other compilers as well, as I
assume that 
> cross studio's printf format strings are pretty standard.

They are, when they're run on the target--however, debug_printf is run
on the host...

--
Paul Curtis, Rowley Associates Ltd  http://www.rowley.co.uk
CrossWorks for MSP430, ARM, AVR and now MAXQ processors

That did the trick. Thanks Paul. 

On Monday 07 November 2005 4:44 pm, Paul Curtis wrote:
> Hi Micah,
>
> > I'm trying to output a signed int with printf() in crossworks
> > so that I can get some feedback in the debug window.
> >
> > It's working, but it's not displaying negative numbers
> > properly, it's giving the two's compliment instead, i.e.
> > 65534 instead of -1..
>
> This, I think, is a known problem.
>
> > Is there a format string switch that I can use to force it to
> > be in signed mode? I looked on the net, and in the crossworks
> > docs, and can't find anything. Maybe I'm totally missing
something.
> >
> > Currently I'm just doing this:
> > signed int x;
> > (code)
> > debug_printf("%d\n", x);
>
> You could try:
>
> debug_printf("%ld\n", (long)x);
>
> > This may apply to other compilers as well, as I assume that
> > cross studio's printf format strings are pretty standard.
>
> They are, when they're run on the target--however, debug_printf is run
> on the host...
>
> --
> Paul Curtis, Rowley Associates Ltd  http://www.rowley.co.uk
> CrossWorks for MSP430, ARM, AVR and now MAXQ processors
>
>
>
> .
>
>
> Yahoo! Groups Links
>
>
>


The 2024 Embedded Online Conference