A quick c programming survey question - Page 5

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: A quick c programming survey question

Quoted text here. Click to load it

In my experience, embedded systems code is only meant to work
on one system.

Quoted text here. Click to load it

Right.  But there's no point it trying to write that driver
code in a "portable style" since the hardware being manipulated
isn't portable.

--
Grant Edwards                   grante             Yow!  I'm in ATLANTIC CITY
                                  at               riding in a comfortable
We've slightly trimmed the long signature. Click to see the full one.
Re: A quick c programming survey question
Quoted text here. Click to load it

Not my experience. I've had to port very large projects from CPU to CPU over
the years. The code tends to last longer than the availablity of the
processors ;).

Re bitfields: if they're being used as efficient boolean storage, alignment
etc is irrelevant. This is probably why they're in the standard. For control
of hardware, they're "highly non-portable" (as I've already quoted from
Brian Kernighan), but as has been noted, some compilers provide
(non-standard) workarounds. I agree with the comment re hardware interfacing
belonging at the driver layer - quite often I have a totally different port
implementation in changing CPUs, let alone bits - so it's an environment
issue which will inevitably be revisited.

Steve
http://www.fivetrees.com
http://www.sfdesign.co.uk



Re: A quick c programming survey question

Quoted text here. Click to load it

Agreed - I've seen bitfields for "left" and "right" in a joystick interface
swap position when changing the optimization level. The compiler writers
justifiably pointed to the ANSI spec showing they could do what they
thought appropriate.

They later forced the compiler to use "intuitive" ordering, but that was
lesson enough for me to never use bitfields again for accessing sections of
a hardware register.

One other advantage of #defined constants is that you can combine separate
logical groups and read or write them with a single operation, spurious
example:

        response = getBits( readChannel, RCIN | RCERR );

Of course, we never use RCIN + RCERR, do we?

Peter.

Site Timeline