Re: Portability: Harmony between PC and microcontroller



Tomás Ó hÉilidhe wrote:

On May 6, 12:33 pm, Chris Dollin <chris.dol...@xxxxxx> wrote:

That just means that those microcontrollers aren't a natural fit
to C, so programmers writing looks-like-C for them need to be
aware that natural-C idioms might not work as nicely.


This is what I'm against. When I first started programming in C for
embedded systems, I was weary of the compiler's compliance to the
Standard. I was hesitant to rely on rules from the Standard when it
came to things like:
* Minimum size of integer types
* Behaviour of overflow
* Existance and usage of a stack

Having written a fully working program though in C for embedded
systems, and also having looked at the assembler produced to check
what it's actually doing, I've seen that my embedded compile is
extremely compliant. I defined an object as "long unsigned", and lo
and behold the assembler produced used four bytes to store it (even
though it can only do arithmetic on 8-Bit numbers).


I don't see a problem here.


The problem comes with writing portable code.

No, it doesn't. Not if the compiler conforms to the standard.

For instance, I'm
currently writing code to implement an internet protocol router. The
code show be able to run on both a microcontroller and on a PC.
However, if the code uses "int" then the code will be less efficient
on a microcontroller.

Your problem is not with portability; it's with performance.
Different platforms can have differing performance profiles
at whim, and portable code may need tweaking for best performance
on /any/ of them. Singling out performance issues on 8-bit
micros and thinking everyone should write code so that it
(by /hypothesis/) performs equally (well, badly) on those
implementations is, I think, obsession over microefficiency.

--
"The one you're playing, I think." /The Lion Game/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

.



Relevant Pages

  • Re: Portability: Harmony between PC and microcontroller
    ... so programmers writing looks-like-C for them need to be ... I was hesitant to rely on rules from the Standard when it ... and behold the assembler produced used four bytes to store it (even ... The problem comes with writing portable code. ...
    (comp.lang.c)
  • Re: Segfault City
    ... Those who ignore the standard library condemn themselves to rewriting it. ... programmers have to use a dictated and not fully standard compiler. ... I'm saying that to rely on character ordering that is not guaranteed ...
    (comp.lang.c)
  • [PATCH] Fix misspellings collected by members of KJ list.
    ... - * writting a Wavelan ISA driver for the MACH microkernel. ... there are two posibilities reading or writing. ... - * on non x86 architectures, so if you are writting portable code, ...
    (Linux-Kernel)
  • Library Design, the script kiddies nightmare.
    ... good across the board of assembler programming. ... With languages that have the capacity, libraries of reusable code make ... comes at a cost that some of the older assembler programmers will not ... The virtue of writing code in this modular format is that you can use ...
    (alt.lang.asm)
  • Re: Whats the deal with C99?
    ... programmers need or want. ... couple of marginal C99 implementations which can only do so because ... a major loss for GCC, the C standard, and the C community in general. ... If the C standard committee merely added APIs for these into ...
    (comp.lang.c)