On portable C programming (was: libraw1394 struct layouts...)

Kevin D. Clark kevin_d_clark at comcast.net
Thu Jan 8 12:11:48 EST 2009


Ben Scott writes:

> On Wed, Jan 7, 2009 at 11:31 PM,  <VirginSnow at vfemail.net> wrote:

> > One way might be to expose a function/method for
> > accessing each structure member.
> 
> That's probably the only truly portable way, but it's cumbersome as
> hell.

Yeah, it is cumbersome.  Sometimes programming is hard.  It is hard
work to make sure that something works right in all cases.  Hopefully
every project worth doing has somebody on staff who cares about
details like this.

The thing is, you don't have to do this work until you run into an
architecture/compiler that absolutely does not do what you want it to.
Until then your code is fine.  If you (not anybody in particular)
think that code written in this manner isn't right and you'd prefer to
use something else, stop using Linux or any other real-world OS.

Basically, when you play with bits, you might get bitten.  If the
programmer who writes the code inserts enough self-checks into the
code and writes their code rigorously enough, everything is fine.  It
is also is a requirement that the designers of the system at least
think of interoperability problems up-front rather than after the
system gets deployed somewhere.  If the project doesn't have people
who can think in this way, then there will be problems.  Oh well.

...

This is why I was so angry at the programmer who removed the asserts
from my code in the blog posting that I cited.  What he did was
basically the equivalent of ripping out all of the gauges and
indicator lights from the dashboard of your car, all while uttering "I
didn't understand these things so I ripped them out".  Well, sometimes
indicator lights and gauges are very important.

Regards,

--kevin

PS All of this has one other collary: eventually, you arrive at the
   conclusion that if a given value has to be 
   streamed/passed/stored/whatever and ultra-high performance is not
   the primary goal, it is frequently better to
   stream/pass/store/etc. things as text.

-- 
"No, no, no, don't tug on that. You never know what it might
 be attached to."
-- Buckaroo Banzai


More information about the gnhlug-discuss mailing list