Re: writing drivers using C++



Ulrich Eckhardt wrote:

I beg to differ, exceptions and RTTI require some code.

No, both can be done at compile time, though the implementation
may greatly differ from how it's done usually. Been there, done
that, programming µC with tight RAM constraints, but loads of
program ROM. However I've done that with pure C and a lot of
helper macros then.

For example exceptions can be done using a global backtrace table
instead of using a stack unwind approach (in multithreaded
environments you'd use thread local storage for those). RTTI can
be implemented in a similair way: Primitive types are dealt with
at compile time. Class instances carry a pointer (similair to a
vtbl) with them, that directs to a static classinfo structure.
All RTTI stuff can be done at compile time, but of course it's
easier to implement with a runtime.

I'd say that is a bad reason. Firstly, C integrates pretty well
with C++, so you can always use some C code, just like you can
step to assembly today. I'd much rather say that C++ is a very
sharp tool, and most programmers can't use it safely.

You can of course dive deep into the internals of C++ with the C
subset and assembler of course, but the resulting code will be
tied to a certain compiler or runtime implementation. And then
don't forget that you can't access identifiers by ther mangled
names from within C++ code, unless you make use of some probably
unavaliable #pragma.

Just have a look on how to access COM/ActiveX modules from pure
C, it's an utter mess. Microsoft developed those concepts with
only their own C++ compilers in mind and it took other compiler
vendors some iterations to adapt their's to the new "needs". The
problem is, that C++ doesn't define a strict ABI (yet), which in
the early days of C++ has lead to a lot of different ways how
polymorphism, RTTI, exception handling and the lot were
implemented (at compile time BTW). Today it's done the same way
by most compilers, though IMHO the way it's done is not really
the best one.

Well, binary objects are a pain in the ass either way, whether
it's Linux that changes its internal APIs or whether it's the
C++ compiler matters little. I'd say that this could be fixed
with tools though, but nobody's writing them. :/

They're not, as soon as you got a strict ABI. Any compiled
program is a bianary object of some sort, and somehow even the
oldest ELF binaries happyly run on even the newest *nix-boxes as
long at the accompanying libraries are installed - or you've got
it even purely static in an a.out.

And at least on a programming language level something like an
ABI should be the least problematic thing to tie down - I still
wonder why it hasn't been done for C++ in the first place. Maybe
because C never needed a pinned down ABI, as CPU architectures
implicitly brought something like an ABI with them and things
like exception handling or RTTI never were done on a language
level, but on a third party library/runtime level.

And one thing's for sure: My favor of C over C++ comes not from
an ignorance of C++, but from being fed up with it. I took my
first steps in the OOP programming world with C++, and nearly
all my programs for the next 10 years since then were written in
C++. But there more I worked with it, the more I figured it's
flaws, from a technical purist's point of view. I can't pin down
my feelings about it, but to me C++ is something like Lego
technic, while C feels like crafting a machine from bare
materials in a workshop - it may take longer, be harder, but
you've got far more possiblities to express your ideas, while
C++ gets you faster to a result. But this is a highly
subjective, even emotional view I got. Other people probably
differ, and it's good that way. Still I think C is one of the
fines programming languages in existance.

Wolfgang Draxinger
--
E-Mail address works, Jabber: hexarith@xxxxxxxxxx, ICQ: 134682867

.



Relevant Pages

  • Re: ///Wannabee Rants
    ... I am reading and reading, and it seems none of you are really able to explain to me why this typechecking is so important, and neither how it works. ... Plus the example Sevag showed was just a couple of lines. ... For the code I posted latly, all the partisipants, having some programming background, understood exactly. ... Now I understand why your compiler took several seconds to compile a 5 liner when tested over a year ago. ...
    (alt.lang.asm)
  • Re: VB .NET OOP
    ... > Compile and run, apparently, if it's like VB6. ... My name isn't Eddie. ... I'd written and published about programming since ...
    (comp.programming)
  • Mentoring a Coworker
    ... Lately I've had a problem trying to mentor a co-worker. ... He lacks some of the most basic programming skills. ... I don't mean to insult him, casually speaking, he sounds like ... co-worker asked him every half an hour or so "Did you compile?" ...
    (comp.programming)
  • Re: A summary of the #include liability
    ... >> If you merely intended to show that the .NET and CLI are doing what I ... the same notation could not be used at compile time. ... the time has come to be serious about macro-free C++ programming." ...
    (comp.lang.cpp)
  • Re: year 11 maths survey
    ... > whilst it is true that some of my C programs will compile under a C++ ... I thought APL was an old language? ... I was programming a beeb then, ... I wonder if anyone else ever heard of UFI (a cross between C and BASIC ...
    (comp.programming)