[ECOS] looking for tips on programming in C for embedded systems
Thu Dec 20 10:01:00 GMT 2001
> Is there a good article anywhere on tips for programming on
> eCos (and low-memory/MIPS-scarce systems in general) ?
(haven't read it myself though).
> I have been coding in C for years, but I found one
> new thing already while working with eCos: don't -
> int foo ()
> char data;
> - rather -
> int foo ()
> char *data;
> data = malloc (1024);
> if (!data)
> free (data);
> - the latter doesn't eat precious stack space.
but does require more runtime resources (time to allocate, space for code
and the heap), and the risk of running out of memory. It's less
deterministic. Maybe it would be better as a global even. So it's another
approach, but not necessarily the best - it depends on the situation.
Choosing a larger stack may still be the best option.
A general principle would be to allocate up front what you know you'll
> What I am looking for is the definitive top 20 tips
If you're willing to collate a list, we could add it to the FAQ. I'll add
For an embedded system, don't waste overhead with checking the validity of
parameters all the time. Instead do it with asserts so it happens in
"debug" builds, but disappears in "production" builds.
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
More information about the Ecos-discuss