Re: 3rd party Device driver development tool or pure- wdm driver development..Which is the

Max,

You see, in C++ the “<<” operator isn’t necessarily a shift operator. The
“<<” is just a name, you can leave it bound to the shift operator, or you
can bind it to something else. Iostreams binds it to stream operations, but
there’s no reason why I can’t define my own meanings within my own classes.

This is a *major* difference between C and C++: in C, a function or an
operator is global, while in C++, although it can still be global, it has
whatever meaning that is defined within the class of which it’s a member.
So, if you say A << b, you’re not necessarily saying shift A left by b
positions - the actual meaning of the “<<” depends on the class of A, and on
the class of b, and on whether there’s an “<<” operator defined for that.
For example, I can define things so that A<<4<what I want it to look like: the “<<” between A and 4 means indexing, the
other “<<” means assignment. Actually, I can define things so that
A<<“hello”<
And today, I look at “<<” or “>>” and I think streams before I think shifts.

Likewise, nothing in C++ prevents me from defining a printf function inside
my classes, or even outside, and it doesn’t even need to have the same
parameters as the standard global function. For example, in OpenGL you have
functions glVertex2d(i,j), glVertex3d(i,j,k),glVertex2f(x,y), and so on, and
it’s a pain to remember. So, what do I do to teach it to my students ? I
define glVertex(i,j), glVertex(i,j,k), glVertex(x,y), and so on, and the
type and number of parameters is negotiated by the polymorphism - no need to
remember a shitload of acronyms, they’re relegated to a .h file.

This one point - that the semantics of functions and operators depend on the
class - requires a shift in design philosophy. The semantics of a function
is the semantics that is defined in the class of the object. For example, if
I have functions in C such as

NTSTATUS DoSomethingWithanIRP(irp, parameters…)
NTSTATUS DoSomethingWithaDriverObject(drvobj, parameters…)
NTSTATUS DoSomethingWithaDeviceObject(dvcobj, parameters…)

in C++ I can make three member functions, something like

NTSTATUS irp::DoSomething(parameters…)
NTSTATUS drvobj::DoSomething(parameters…)
NTSTATUS dvcobj::DoSomething(parameters…)

and the semantics of DoSomething() change depending on which object is it
been called within. Then, if tomorrow I have to implement a DoSomething
function for a new kind of object, all I have to do is to define it, so that
I can use it the same way:

NTSTATUS mynewobj::DoSomething(yet other parameters…)

and when I want an object to DoSomething, I just call DoSomething and let
the class know what it means. In fact, any time you have a big switch
statement in a program, you’re making a case for resorting to member
functions instead.

To make the example even more dramatic, I could also have a global function
such as

::DoSomething(blah blah)

You see, the semantics of a function depends on the class within which it’s
declared, it’s no longer necessarily fixed and global. If you want to know
what a function does, you must look at the .h file ! That’s the C++ way.

Alberto.

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Thursday, November 01, 2001 9:04 PM
To: NT Developers Interest List
Subject: [ntdev] Re: 3rd party Device driver development tool or pure
wdm driver development…Which is the best???

> Quicker to write than printf(“%x\n”,4*(A+1)), or even cout<<4*(A+1)<> and I don’t know if it isn’t easier to parse too.

printf() is the best since it does not use hidden semantics.
Also - using the SHIFT operators for writing to a stream is a bit illogical.

Max


You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com