EmbeddedRelated.com
Forums

printf format specifer

Started by hc08jb8 February 18, 2005
Hi,

I am using IAR 3.2. To output some simple data:-

          unsigned int dcount,counter,adc,timer;

          ....
          printf("%d,%d,%d,%d\n",dcount,timer,counter,adc); 
          
The format specifer screws up the output, eg: if timer= 0xFFFF; I 
dont get 65535 on the console. I read thru the docs for setting 
CLIB/DLIB etc, as well as tried other specifiers, no luck. Any clues?

Thanks
Jay





Beginning Microcontrollers with the MSP430

Hi,

Try to use %u instead of %d !!!

Boby

--- hc08jb8 <jameelh@jame...> wrote:

> 
> Hi,
> 
> I am using IAR 3.2. To output some simple data:-
> 
>           unsigned int dcount,counter,adc,timer;
> 
>           ....
>          
> printf("%d,%d,%d,%d\n",dcount,timer,counter,adc); 
>           
> The format specifer screws up the output, eg: if
> timer= 0xFFFF; I 
> dont get 65535 on the console. I read thru the docs
> for setting 
> CLIB/DLIB etc, as well as tried other specifiers, no
> luck. Any clues?
> 
> Thanks
> Jay
> 
> 
> 
> 
> 



		
__________________________________ 
 
 



> I am using IAR 3.2. To output some simple data:-
>
>           unsigned int dcount,counter,adc,timer;
>
>           ....
>           printf("%d,%d,%d,%d\n",dcount,timer,counter,adc);
>
> The format specifer screws up the output, eg: if timer= 0xFFFF; I
> dont get 65535 on the console. I read thru the docs for setting
> CLIB/DLIB etc, as well as tried other specifiers, no luck. Any clues?


Hi!

What did you get?

If you got "-1" then you got the right answer, however you used the
wrong formatter.  (As someone already pointed out you should use the %u
modifier.)

If you got gibberisch then I assume that you simply forgot to include
the stdio.h header file.

Just to be safe, I tried your example using both clib and dlib, and
they worked as expected.

    -- Anders Lindgren, IAR Systems
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Hello Anders,

Yep, the %d gave a -1 and the %u worked fine. :-)

Meanwhile, in another project while trying to use the printf I get:-

Error[e16]: Segment CODE (size: 0x1352 align: 0x1) is too long for 
segment definition. At least 0x394 more bytes needed. The problem 
occurred while processing the 
segment placement command "-Z(CODE)CODE0-FFDF", where at the 
moment of placement the available memory ranges were "CODE:f022-ffdf"

I tried switching the CLIB/DLIB etc, same thing, I comment off the 
printfs and links ok.

Thanks
Jay



--- In msp430@msp4..., Anders Lindgren <Anders.lindgren@i...> 
wrote:
> 
> 
> > I am using IAR 3.2. To output some simple data:-
> >
> >           unsigned int dcount,counter,adc,timer;
> >
> >           ....
> >           printf("%d,%d,%d,%d\n",dcount,timer,counter,adc);
> >
> > The format specifer screws up the output, eg: if timer= 0xFFFF; I
> > dont get 65535 on the console. I read thru the docs for setting
> > CLIB/DLIB etc, as well as tried other specifiers, no luck. Any 
clues?
> 
> 
> Hi!
> 
> What did you get?
> 
> If you got "-1" then you got the right answer, however you used
the
> wrong formatter.  (As someone already pointed out you should use 
the %u
> modifier.)
> 
> If you got gibberisch then I assume that you simply forgot to 
include
> the stdio.h header file.
> 
> Just to be safe, I tried your example using both clib and dlib, and
> they worked as expected.
> 
>     -- Anders Lindgren, IAR Systems
> -- 
> Disclaimer: Opinions expressed in this posting are strictly my own 
and
> not necessarily those of my employer.




Oh, nevermind, I set the printf formatter in the Library option to 
small and everything is OK.

Thanks anyways. :-)


--- In msp430@msp4..., "hc08jb8" <hc08jb8@y...> wrote:
> 
> Hello Anders,
> 
> Yep, the %d gave a -1 and the %u worked fine. :-)
> 
> Meanwhile, in another project while trying to use the printf I get:-
> 
> Error[e16]: Segment CODE (size: 0x1352 align: 0x1) is too long for 
> segment definition. At least 0x394 more bytes needed. The problem 
> occurred while processing the 
> segment placement command "-Z(CODE)CODE0-FFDF", where at the 
> moment of placement the available memory ranges were "CODE:f022-
ffdf"
> 
> I tried switching the CLIB/DLIB etc, same thing, I comment off the 
> printfs and links ok.
> 
> Thanks
> Jay
> 
> 
> 
> --- In msp430@msp4..., Anders Lindgren 
<Anders.lindgren@i...> 
> wrote:
> > 
> > 
> > > I am using IAR 3.2. To output some simple data:-
> > >
> > >           unsigned int dcount,counter,adc,timer;
> > >
> > >           ....
> > >          
printf("%d,%d,%d,%d\n",dcount,timer,counter,adc);
> > >
> > > The format specifer screws up the output, eg: if timer= 0xFFFF; 
I
> > > dont get 65535 on the console. I read
thru the docs for setting
> > > CLIB/DLIB etc, as well as tried other specifiers, no luck. Any 
> clues?
> > 
> > 
> > Hi!
> > 
> > What did you get?
> > 
> > If you got "-1" then you got the right answer, however you
used 
the
> > wrong formatter.  (As someone already pointed
out you should use 
> the %u
> > modifier.)
> > 
> > If you got gibberisch then I assume that you simply forgot to 
> include
> > the stdio.h header file.
> > 
> > Just to be safe, I tried your example using both clib and dlib, 
and
> > they worked as expected.
> > 
> >     -- Anders Lindgren, IAR Systems
> > -- 
> > Disclaimer: Opinions expressed in this posting are strictly my 
own 
> and
> > not necessarily those of my employer.