A quick c programming survey question - Page 3

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

A good example of this is the UART used in the eZ80 series, which is
identical in its interface to the 16450 types.

Quoted text here. Click to load it

And registers which do something when you read them... it's quite
common, for example, for the accessing of an interrupt status register
to acknowledge the interrupt.

I think there is a case for a type qualifier (say "hardware") to be
implemented, which allows the compiler writer to implement the dirty
kludgy bits in the privacy of his own code, leaving the user with a
pristine readable source. It's already commonly done with interrupt
service routines, for example.

Paul Burke


Re: A quick c programming survey question
"> Do you (your company) prefer to:
Quoted text here. Click to load it
 
b)

Re: A quick c programming survey question

Quoted text here. Click to load it

B
--
"Just machines that make big decisions
 programmed by fellas with compassion and vision."
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

(a) would be nice if the C standard made it practical. So I use (b).


--
Mike Page BEng(Hons) MIEE           www.eclectic-web.co.uk

Re: A quick c programming survey question

Quoted text here. Click to load it

Which hits the nail on the head, and was why I asked
people not to comment.  Though is not a problem,
I'd already decided that I'd collated enough answers

tim




Quoted text here. Click to load it



Re: A quick c programming survey question - Update!
Ok, so it seems that more people have selected B than A.
This slightly surprises me because most of the places that
I have worked use 'A' (not on my advice), but then that
was why I asked.  But as someone has pointed out the
experience of the posters to the group is above the average
so that should be the reason.

The actual question was an interview question (asked to
a colleague).  It was a telephone interview so there was
little scope for discussion.

Those of you who answered "it depends" have failed (my
decision) as the code requirement is one of 'conformity'
and 'reusability' from one project to the next (and
reusability of the programmer's knowledge from one
project to the next).

I suppose those that have answered 'something else'
would not have done so in an interview (unless they had
already decided that they didn't want the job) and can
decide for themselves if they 'passed'.
Feel free to disagree with this assumption if you really
would argue the point in a telephone interview (which
here is a filter into a 'real' interview).

The answer that the interviewer wanted was 'b'. So
those people pass (as long as they get the other
questions correct!)

My colleague was pissed, as he said 'a', on no more
experience than what we do currently.  He asked me the
question, I instantly said 'b' and when asked why I said
"because bits are not portable" (correct answer - been
there..., to be avoided big time) which pissed him off
even more.

But on reflection perhaps he has a right to be pissed.
IME many people don't know that bits are not portable
(or perhaps they decide that they don't care), but
they still might prefer Option 'b' because:

1) they consider it neater
   SetBit( &register_name, bit_name );
is a arguably tidier than
   register_name->bits.bit_name = 1;

2) It can provide error checking missed by some
compilers, which don't object if you try to put
more bits into the element than it actually has.

3) It can provide a uniform interface with reading
bits from locations that are not accessed by a single
read such as the register on an I2C device for which
the struct method will not work automatically.

(and some, who know bits aren't portable, might
still prefer 'a', though god knows why!)

So if the interviewer just wanted to find out if the
interviewee knew that bits aren't portable he should
have asked using a less roundabout question to
establish this and addressed the 'style' issues separately
(which I am sure my colleague would have got right).

Anyone care to comment?

tim



Re: A quick c programming survey question - Update!
Quoted text here. Click to load it


I never use a) for memorymapped I/O since I discovered that GCC-ARM in that
case tries to do a byte-access on a 32-bit register (not byte-addressable).
The rest of the register of course got thrashed.

But I still use a) for variables in memory, since the compiler (at least
GCC) nicely realigns things when a field size has to be changed. Just
changing one field in an structure and recompiling is mucht nicer than
searching all the code. And I'm not so fond of macros.

Regards,
Arie de Muynck



Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

If you had said that portability was important, then you get
different answers.  A piece of code that is only going to run
on a single processor model is written differently than one
that has to run on multiple architectures.  A lot of embedded
code doesn't need to be portable.  There absolutely no point
trying to port code that sets up times on an Hitachi H8/3062B
microctonroller to a VAX.

Quoted text here. Click to load it

Beacause the vendor provided all the structure bitfield header
files and none of the code is going to be portable anyway?

Quoted text here. Click to load it

Asking somebody whether A or B is better without stating all
the requirements, is deluded.

--
Grant Edwards                   grante             Yow!  Alright,
                                  at               you!! Imitate a WOUNDED
We've slightly trimmed the long signature. Click to see the full one.
Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

I'm about half in agreement with you (it wasn't me who originally
phrased the question).

For the other half, the fact that this was an interview situation
was relevant.  It doesn't seem unreasonable to me for the
interviewer to assume that the interviewee can work out for
themselves that portability of code (and ideas) might be an
important thing to convey.

But, in making my question as concise as possible I decided
to leave this information out.  With hindsight this was a
mistake and for that I apologise.

tim




Re: A quick c programming survey question - Update!

  I have to admit, I am a little lost at the whole point you
are trying to make ?

<snip>
Quoted text here. Click to load it

Shame that was not specified in the original question, then ?

<snip> 3) It can provide a uniform interface with reading
Quoted text here. Click to load it

Still not easy to find the point...

  BOOLEAN BITS, by their nature are not portable.
In embedded systems, they most commonly apply to hardware flags.
  Someone who thinks that a change in SW style can somehow create
'more portable bits' probably should not be let near low level code!

  The embedded systems I work on have never had to change HW targets,
so I code for best maintainance/interrupt integrity.
-jg


Re: A quick c programming survey question - Update!
On Mon, 17 May 2004 09:31:37 +1200, Jim Granville

Quoted text here. Click to load it


   FWIW, not only have I never used the built-in "bits" facility in C
(answer a) in the original thread), I forgot it was in the language. I
don't recall seeing any code that uses it (outside of k&r).

   Now I at least see the 'agenda' that prompted the original
question. The answers were either a) or not a). I definitely do bit
manipulation by bitwise anding, oring, shifting and complementing,
either directly in the 'main' code or in functions or macros as I see
fit. This generally works (until changing to a processor with a
differen word size, then there are usually other considerations as
well) and is about as portable as can be expected.

Quoted text here. Click to load it

   I recall an interview I had maybe ten years ago. The company had
the same C code running on two different 8-bit microcontrollers, one
was, IIRC, an 8051, and the other was some other unrelated
(non-compatible) architecture. They were asking me questions to see
how much I knew about writing "portable" C code. I gave what answers I
could, about isolating I/O operations to separate functions that are
different for each chip and the main "portable" code calls those
functions to do I/O.
   I didn't get a job offer, and looking back it's just as well (I
vaguely recall the products were related to "home networking" for
appliances like washer/dryers and refrigerators, so they could be
controlled remotely to do things like reduce peak power consumption -
this was hot at the time but I haven't heard anything about such
applications in years). It seemed to me at the time (though I could be
wrong, I can't think of another reason to do this) that they did this
for manufacturer/vendor independence - so that in case one chip maker
went out of business, they would have the code and hardware designed
with the other chip ready to manufacture. Perhaps they also played the
manufacturers and vendors against each other, saying "We've got the
code running on your compettitor's chip right here, and we're going
with the lowest priced solution at a few million units/year" in an
effort to negotiate lower prices. But it seemed like they were going
to great expense to be able to say they had "portable code" running on
both these chips.

Quoted text here. Click to load it

-----
http://mindspring.com/~benbradley

Re: A quick c programming survey question - Update!
On Sun, 16 May 2004 12:54:20 +0200, "tim"

[snip...snip...]
Quoted text here. Click to load it

No, I prefer to be honest and to the question:

"Do you (your company) prefer to:

a) Create a 'bits' structure for each register and access using
the dot or arrow operator.

b) Create a set of bit access functions (or perhaps macros)
and access using those?"

I would have answered "neither" as I did in my original reply, since I
feel that both methods tend to obfuscate rather than clarify.

Quoted text here. Click to load it

There's nothing about which to argue, is there, as the question is what
my preference is?

Quoted text here. Click to load it

No, they answered a rote question. I suspect (as Grant has also implied)
that most working embedded programmers prefer the "|=" and "^= ~"
constructs. I've used the other techniques when doing maintenance
programming (Rule #1 of maintenance programming: Don't change the
existing style.) but really don't "prefer" either 'a' or 'b'.


[snip...snip...]

Quoted text here. Click to load it

What nonsense. If this is something that the interviewer actually
believes that the candidate pool may be unsure of, then perhaps he's
fishing in the bottom of the pool and deserves what he pulls out.

--
Rich Webb   Norfolk, VA

Re: A quick c programming survey question - Update!

Quoted text here. Click to load it


As I pointed out in my comment, a very large number of people
with which I (have) work(ed) don't know this.  Quite why this I
do not know.

tim


Quoted text here. Click to load it



Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

Untrue.  I suspect most employers want to hire people that
can think for themselves.  I certainly would give more weight
to candidates that could argue their points intelligently
and disagree with me.

Quoted text here. Click to load it

No, it's a filter to weed out independent thinkers.  This is the
classic Microsoft interview question "why are manhole covers round"
where they accepted only one possible answer as "correct".

Quoted text here. Click to load it

Your colleague should be happy, since now he doesn't have to work
with people like that.

--
Darin Johnson
    Gravity is a harsh mistress -- The Tick

Re: A quick c programming survey question - Update!
Quoted text here. Click to load it

I agree, but I think you'd also agree there is a point at which that alone
isn't worthwhile.

For example, we had an interviewee who thought that "Getting code to market
fastest" was the way to do it, and forget about any processes, reusability
or maintainability of the code. He argued tooth and nail for it. We didn't
hire him.

Quoted text here. Click to load it

That would be fine, unless their points are asinine.

Quoted text here. Click to load it

I don't think that's what the original poster meant. It's more of a field
question of "is this guy aware of the pitfalls of a common construct and
does he know when and when not to use them"?

I personally don't mind independent thinking or using the bitfield
construct, provided it's knowingly applied, rather than haphazardly by the
ignorant.

-->Neil



Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

From personal experience I find this a hard thing to do
during a telephone interview.  You don't get the necessary
feed-back if the guy hasn't understood your idea.
I leave discussion of ideas to real interviews

Quoted text here. Click to load it

Perhaps,  as I know of no-one that's got the job I can't tell

Quoted text here. Click to load it

But at least you have a chance of knowing the answer
that they want :-)

Quoted text here. Click to load it

I'm inclined to agree with you.  As I got 'all' of the questions
correct he suggested that I should go for the Job, but I decided
that it didn't sound like me.

tim

Quoted text here. Click to load it



Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

Because manholes are round. :)

--
Grant Edwards                   grante             Yow!  Mr and Mrs PED, can I
                                  at               borrow 26.7% of the RAYON
We've slightly trimmed the long signature. Click to see the full one.
Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

Not where I live, they're not.

tim

Quoted text here. Click to load it
can I
RAYON
the



Re: A quick c programming survey question - Update!
Quoted text here. Click to load it

Ah, that's where you're wrong.  Microsoft has changed the value
of 'round'.

--
Grant Edwards                   grante             Yow!  HAIR TONICS, please!!
                                  at              
We've slightly trimmed the long signature. Click to see the full one.
Re: A quick c programming survey question - Update!

Quoted text here. Click to load it

What was their "correct" answer.

I've seen both round and square ones, so the question sounds dumb to me.

--
Burn the land and boil the sea,
 You can't take the sky from me.

Site Timeline