Re: Making small executables from h8300-coff-gcc

Hello,

> >If I use sprintf like this: > >#include "ioh8s2148af.h" >#include > >unsigned char string[] = "hello world"; > >int main (void) >{ > unsigned char tmp[200]; > > sprintf( tmp, "%s", string); > return (0); >} > >I end up with an executable of 32K. It links heap manager and all other >things, such as:
[snip...snip...]

Yup. The printf() family is required to do all sorts of magical formatting, and that takes code.

Some microcontroller implementations have "reduced capability" printf()- style functions for just the reason you've seen. For example, the Imagecraft AVR C compiler (ICCAVR) has three "sizes" of library code for the printf() family (portions snipped from the help file):

basic: only %c, %d, %x, %X, %u, and %s format specifiers without modifiers.

long: %ld, %lu, %lx, %lX are supported, in addition to the width and precision fields. floating point: adds the %f specifier.

Each one needs more space for the library code.

If at all possible, avoid the printf() family altogether on smaller microcontrollers. It's possible (and frequently necessary) to do your own string formatting.

--
Rich Webb   Norfolk, VA
Reply to
Rich Webb
Loading thread data ...

Probably yes, or change to a compiler like the IAR one that has a reduced printf available from the outset.

Reply to
Jakob Engblom

Either that, or shun printf() and friends.

-- Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

Reply to
Hans-Bernhard Broeker

The normal C library used with GCC for embedded is newlib, and newlib also comes with a reduced capability printf (no floating point). It's called iprintf(). I suggest the OP try that!

Jifl

--
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine
Reply to
Jonathan Larmour

Rick

I have a simple source file for printf (no floating point support) that I simply link in to my H8 projects and I don't get loads of other garbage along for the ride.

Email me (or post here) if you would like a copy. (The email here does work)

Andy G.

Reply to
Andy G

Well, in an embedded application particularly, I'd prefer it if he used strncpy... :)

Reply to
Lewin A.R.W. Edwards

Andy, Thanks!

I've just did the same.

I found some source for sprintf and sscanf which is configurable (float or no float etc). I have used the IAR source actually which i found on a demo CD.

I have a next question which you can answer maybe. I have definied a section for uninitialized data like this:

int someData[200] __attribute__ ((section("MySection")));

"MySection" is RAM memory.

This wil cause that in the S-record file the section is included but it is uninitialized data.

How can I tell the linker to handle it as uninitialized data?

BTW: I use Kpit GNU 0303-elf with HEW

Rick

Reply to
Rick

Not claiming to be an expert here, but is what you are after something like:

.bss (NOLOAD) { ... *(.MySection) ; ... }

in the .xr (?) file that describes to the linker where to locate segments.

Sorry to be woolly - working from shaky memory.

Andy

Reply to
Andy G

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.