Re: writing drivers using C++



Rainer Weikusat wrote:
David Schwartz <davids@xxxxxxxxxxxxx> writes:
On Sep 10, 1:23 am, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:
C++ has support for automatically invoking subroutines in various
cases (constructors, destructors and overloaded operators), which
means that just looking at a piece of code is not sufficient to
determine what will actually happen at runtime when this code is
executed.

So does C. For example, invoking a function through a function pointer
makes it unclear by looking at the code what will happen at runtime.

You are trying to sidestep the issue by writing about something
entirely different from my text above. C++ supports automatic
subroutine invocation as result of statements that are not technically
function calls. C doesn't.

Yep, and that's a good thing, because it allows you to shift your attention
to a different level of abstraction. However, I'm not going to argue the
merits of this. Still, what strikes me most was your assertion following
the above quote:

It is additionally necessary to know the implementations of
any classes which may be used in it.

By the same logic, that would mean that you also have to know the
implementation of any plain function involved somewhere. No, you are still
coding against an interface - when the implementation starts mattering to
you, the interface is typically badly implemented and documented,
regardless of the language used for it.

In contrast to this, every subroutine invocation in C is explicit.

Every subroutine invokation has to be coded manually, you can't delegate it
because there is nothing you can hook into, like the mentioned function
calls following the scope of an object. Writing the same cleanup code
produces LOC but doesn't add anything to the final executable. Anyway, all
you have to do in order to get to the subroutine calls is to be aware of
things, like you seem to be. You only have to know that creating an object
or destroying it involves code that is executed, even though there is
nothing explicitly calling a function. Nothing new compared to C
initialisations, just that the possibilities have been enlarged.

Uli

.



Relevant Pages