Hi

volatile int i;
i=7;
stdout=STREAM_USER;
printf("%s", i);

Wont work. But "printf("%c", i); "  results the character with the ASCII code 7. Strings and characters aren't the problem though. As soon as I use something other than "%c/s" my program hangs. It doesn't make a difference if I use int, char or directly the number.

What does "printf("%d", 7);" do on your system?
Well I would expect the same output like: "printf("%c", 7 + 48);" , the ASCII character "7".

I figured out that I only get garbage when I do something like "printf("%s", 'H');". The code is wrong and causes a "Bus error" on my computer. Something like this works fine:

char s[2] = {'H', '\0'};
printf("%s", 's');

Or just "H"

In the other cases my program hangs.

Defining putchar didn't work. It didn't compile and I don't know how to make it.

PUTCHAR(char c)
{
  usart_putc(c);
}

I get this error:

sdcc -mpic16 -p18f2550  i2cIF.c
i2cIF.c:26: error 141: two or more data types in declaration for 'type_specifier_list type_specifier'
i2cIF.c:28: error 103: code not generated for 'putchar' due to previous errors
-:0: error 103: code not generated for 'main' due to previous errors
-:0: warning 85: in function main unreferenced local variable : 'buf'
make: *** [all] Error 1

BTW "printf_small" and "tiny" don't work at all.

Any ideas?

Anyway. thanx for your effort. Hope we can solve this.

Cheers,
Ezra.


On 28.08.2006, at 02:05, sdcc-user-request@lists.sourceforge.net wrote:

Send Sdcc-user mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Sdcc-user digest..."


Today's Topics:

   1. Re: PIC 18F2550 vs. printf/sprintf (Raphael Neider)


----------------------------------------------------------------------

Message: 1
Date: Mon, 28 Aug 2006 00:45:32 +0200
From: Raphael Neider <RNeider@web.de>
Subject: Re: [Sdcc-user] PIC 18F2550 vs. printf/sprintf
Message-ID: <1123446900@web.de>
Content-Type: text/plain; charset=iso-8859-15

Hi,

For example this works:
printf("%s", "Hello");
But this doesn't:
printf("%d", 7);

In some case the program seems to hang, other times I only get garbage.

printf (varargs in general) are pretty easily confused by type mismatches:
Passing a 2-byte int via stack where a 1-byte char is expected can easily
break printf's output, though the remainder should remain unaffected (unless
some vararg pointer is used to write to memory, in which case a size mismatch
in any of the preceeding arguments will cause... say "interesting" results :-(

Printf has been reported to work fine; I have been using it myself successfully.
* You may try to use

PUTCHAR(char c)
{
  /* output c somehow */
}

volatile int i;
i=7;
stdout=STREAM_USER;
printf("%s", i);

to make sure that a two-byte int is passed to printf.
* Also make sure you have selected a proper stdout: AFAIK, stdout is left undefined
by default, which causes an undefined putchar routine to be used.
* You might also need to define a proper putchar routine (using the PUTCHAR prototype macro,
see device/pic16/stdio.h) for use with STREAM_USER.

Of course I can do this conversion by hand. But I want to check out  
the functions in the library. Am I doing something wrong? Is there a  
way to make this work?

Please try the hints above or report more detailed what you already did;
how you want to output your chars;
whether you defined PUTCHAR or not;
any other possibly helpful info ;-)

Regards,
Raphael

_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!




------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

------------------------------

_______________________________________________
Sdcc-user mailing list


End of Sdcc-user Digest, Vol 3, Issue 14
****************************************