Hi,

I trying to derived two different struct from the base one.

typedef struct _COMMON_BASE_
{
.....
}BASE_ONE, *PBASE_ONE;

typedef struct _DERIVED_ONE_ : public _COMMON_BASE_
{
.....
}DERIVED_ONE, *PDERIVED_ONE;

typedef struct _DERIVED_TWO_ : public _COMMON_BASE_
{
.....
}DERIVED_TWO, *PDERIVED_TWO;



and when I run "build" i have error complaining about ":".

I built the same code in VS with no problem.

Could you point what I'm doing wrong ?

thank you

Re: Inheritance by cristalink

cristalink
Thu Feb 10 18:36:42 CST 2005

You need to rename your files from .c to .cpp to use C++ inheritance.

--
http://www.firestreamer.com - NTBackup to DVD and DV


"dave" <dave@discussions.microsoft.com> wrote in message
news:C4317D4B-375E-4375-A86D-C5CB2BAAB0C4@microsoft.com...
>
> Hi,
>
> I trying to derived two different struct from the base one.
>
> typedef struct _COMMON_BASE_
> {
> .....
> }BASE_ONE, *PBASE_ONE;
>
> typedef struct _DERIVED_ONE_ : public _COMMON_BASE_
> {
> .....
> }DERIVED_ONE, *PDERIVED_ONE;
>
> typedef struct _DERIVED_TWO_ : public _COMMON_BASE_
> {
> .....
> }DERIVED_TWO, *PDERIVED_TWO;
>
>
>
> and when I run "build" i have error complaining about ":".
>
> I built the same code in VS with no problem.
>
> Could you point what I'm doing wrong ?
>
> thank you



Re: Inheritance by Ray

Ray
Thu Feb 10 19:19:15 CST 2005

And once you do, be very careful about your use of C++ in kernel mode
(assuming you're talking about a kernel mode driver). MS has a white
paper here: http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx

cristalink wrote:
> You need to rename your files from .c to .cpp to use C++ inheritance.
>

--
../ray\..

Re: Inheritance by 440gtx

440gtx
Thu Feb 10 21:57:42 CST 2005

> MS has a white paper...

If you are lazy, the white paper states this regarding derivation:

"Anything involving class hierarchies or templates, exceptions, or any
form of dynamic typing is likely to be unsafe. Using these constructs
requires extremely careful analysis of the generated object code."

Class hierarchies is basically another name for derivation. The article
goes on to say the reason it is dangerous is "Adjustor thunks, used to
convert between various classes in a hierarchy" might unexpectedly be
pagable or waste memory by being nonpagable when they need not be.


Re: Inheritance by Mark

Mark
Fri Feb 11 06:28:14 CST 2005

440gtx@email.com wrote:
>>MS has a white paper...
>
>
> If you are lazy, the white paper states this regarding derivation:
>
> "Anything involving class hierarchies or templates, exceptions, or any
> form of dynamic typing is likely to be unsafe. Using these constructs
> requires extremely careful analysis of the generated object code."
>
> Class hierarchies is basically another name for derivation. The article
> goes on to say the reason it is dangerous is "Adjustor thunks, used to
> convert between various classes in a hierarchy" might unexpectedly be
> pagable or waste memory by being nonpagable when they need not be.
>
The paper neglects to point out that by 'likely' they mean that 'there
is a small possibility', and that Microsoft's WDF is written in C++ and
makes extensive use of inheritence etc.


--

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

Re: Inheritance by Jeff

Jeff
Fri Feb 11 06:34:24 CST 2005

Or add /TP to your compiler options -- that will force all files to be
compiled as C++ files, regardless of extension.

"cristalink" <cristalink@nospam.nospam> wrote in message
news:e6YPEH9DFHA.1264@TK2MSFTNGP12.phx.gbl...
> You need to rename your files from .c to .cpp to use C++ inheritance.
>
> --
> http://www.firestreamer.com - NTBackup to DVD and DV
>
>
> "dave" <dave@discussions.microsoft.com> wrote in message
> news:C4317D4B-375E-4375-A86D-C5CB2BAAB0C4@microsoft.com...
>>
>> Hi,
>>
>> I trying to derived two different struct from the base one.
>>
>> typedef struct _COMMON_BASE_
>> {
>> .....
>> }BASE_ONE, *PBASE_ONE;
>>
>> typedef struct _DERIVED_ONE_ : public _COMMON_BASE_
>> {
>> .....
>> }DERIVED_ONE, *PDERIVED_ONE;
>>
>> typedef struct _DERIVED_TWO_ : public _COMMON_BASE_
>> {
>> .....
>> }DERIVED_TWO, *PDERIVED_TWO;
>>
>>
>>
>> and when I run "build" i have error complaining about ":".
>>
>> I built the same code in VS with no problem.
>>
>> Could you point what I'm doing wrong ?
>>
>> thank you
>
>



Re: Inheritance by Don

Don
Fri Feb 11 07:42:11 CST 2005

Of course the WDF team had input from the person who wrote the paper and
knew where all the land mines are. I've seen customers who are on the verge
of dropping C++ because they realized that the care needed to use the
language in the kernel is large. Throw in that many of the things people
praise on C++ in user space programming are not allowed (or dangerous) for
the kernel.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



"Mark Roddy" <markr@hollistech.com> wrote in message
news:ODpPoUDEFHA.3492@TK2MSFTNGP12.phx.gbl...
> 440gtx@email.com wrote:
>>>MS has a white paper...
>>
>>
>> If you are lazy, the white paper states this regarding derivation:
>>
>> "Anything involving class hierarchies or templates, exceptions, or any
>> form of dynamic typing is likely to be unsafe. Using these constructs
>> requires extremely careful analysis of the generated object code."
>>
>> Class hierarchies is basically another name for derivation. The article
>> goes on to say the reason it is dangerous is "Adjustor thunks, used to
>> convert between various classes in a hierarchy" might unexpectedly be
>> pagable or waste memory by being nonpagable when they need not be.
>>
> The paper neglects to point out that by 'likely' they mean that 'there is
> a small possibility', and that Microsoft's WDF is written in C++ and makes
> extensive use of inheritence etc.
>
>
> --
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com



Re: Inheritance by Maxim

Maxim
Fri Feb 11 09:31:56 CST 2005

> language in the kernel is large. Throw in that many of the things people
> praise on C++ in user space programming are not allowed (or dangerous) for

Most of such praisers are moving to C# and .NET now.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: Inheritance by Pavel

Pavel
Fri Feb 11 10:08:47 CST 2005

"Mark Roddy" <markr@hollistech.com> wrote in message news:ODpPoUDEFHA.3492@TK2MSFTNGP12.phx.gbl...
> 440gtx@email.com wrote:
> and that Microsoft's WDF is written in C++ and
> makes extensive use of inheritence etc.

After all, they are owners of the compiler and could add special support for c++ in kernel ?

--PA




Re: Inheritance by Don

Don
Fri Feb 11 10:29:11 CST 2005

Well by the time they took out all the things that would mess you up, they
would have a different language, maybe they could call it C+--? There is a
heck of a lot of stuff in the C++ standard that can cause trouble for any
unwary programmer. I have heard a rumor that experiments have been done
with C# in the kernel, but nothing has been announced.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



"Pavel A." <pavel_a@NOwritemeNO.com> wrote in message
news:%23zRHsUFEFHA.4020@TK2MSFTNGP14.phx.gbl...
> "Mark Roddy" <markr@hollistech.com> wrote in message
> news:ODpPoUDEFHA.3492@TK2MSFTNGP12.phx.gbl...
>> 440gtx@email.com wrote:
>> and that Microsoft's WDF is written in C++ and
>> makes extensive use of inheritence etc.
>
> After all, they are owners of the compiler and could add special support
> for c++ in kernel ?
>
> --PA
>
>
>



Re: Inheritance by Pavel

Pavel
Fri Feb 11 11:37:12 CST 2005

"Don Burn" <burn@stopspam.acm.org> wrote in message news:r35Pd.1632$K%6.190@fe03.lga...
> Well by the time they took out all the things that would mess you up, they
> would have a different language, maybe they could call it C+--?

They did something like this for WinCE if you remember.
Before the .net era, there was an "universal C++ front end" and a "safe subset" of C++ that enabled JIT compilation to binary
for target cpu. It seems that .net killed this line of development.

> There is a
> heck of a lot of stuff in the C++ standard that can cause trouble for any
> unwary programmer. I have heard a rumor that experiments have been done
> with C# in the kernel, but nothing has been announced.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
>
>
> "Pavel A." <pavel_a@NOwritemeNO.com> wrote in message
> news:%23zRHsUFEFHA.4020@TK2MSFTNGP14.phx.gbl...
> > "Mark Roddy" <markr@hollistech.com> wrote in message
> > news:ODpPoUDEFHA.3492@TK2MSFTNGP12.phx.gbl...
> >> 440gtx@email.com wrote:
> >> and that Microsoft's WDF is written in C++ and
> >> makes extensive use of inheritence etc.
> >
> > After all, they are owners of the compiler and could add special support
> > for c++ in kernel ?
> >
> > --PA
> >
> >
> >
>
>



Re: Inheritance by Pavel

Pavel
Fri Feb 11 20:26:40 CST 2005

"Don Burn" <burn@stopspam.acm.org> wrote in message news:TC2Pd.1616$hv5.948@fe03.lga...
> Throw in that many of the things people
> praise on C++ in user space programming are not allowed (or dangerous) for
> the kernel.

IMHO those who want C++ or C# in kernel simply lack understanding
of the basic thing - why kernel mode exists and why it is different from user mode.
Those in doubt can meditate a while over the famous etching
of M.C. Escher "Water and Sky"
http://www.worldofescher.com/store/jpgs/P8L.jpg
and it will become very clear to them, that these are two different worlds.

Regards,
--PA




Re: Inheritance by Mark

Mark
Sat Feb 12 07:48:15 CST 2005

Pavel A. wrote:
> "Don Burn" <burn@stopspam.acm.org> wrote in message news:TC2Pd.1616$hv5.948@fe03.lga...
>
>>Throw in that many of the things people
>>praise on C++ in user space programming are not allowed (or dangerous) for
>>the kernel.
>
>
> IMHO those who want C++ or C# in kernel simply lack understanding
> of the basic thing - why kernel mode exists and why it is different from user mode.
> Those in doubt can meditate a while over the famous etching
> of M.C. Escher "Water and Sky"
> http://www.worldofescher.com/store/jpgs/P8L.jpg
> and it will become very clear to them, that these are two different worlds.
>
> Regards,
> --PA
>
>
>
Good grief. This is not mystical or religious. The issue is simply does
the c++ compiler generate functions that are pageable when they ought
not to be.



--

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

Re: Inheritance by Don

Don
Sat Feb 12 08:02:34 CST 2005

There are a heck of a lot of other problems, such as copy constructors,
attempted use of STL, mixing exception handling, etc. Yes it can be argued
that a "good C++ programmer" would know these things, but a lot of people
think they know more than they do!

C++ in the kernel is fine, for a experienced developer who knows his work
will only be passed on to other experieced develoers, otherwise it is a
disaster waiting to happen.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply




"Mark Roddy" <markr@hollistech.com> wrote in message > Good grief. This is
not mystical or religious. The issue is simply does
> the c++ compiler generate functions that are pageable when they ought not
> to be.



Re: Inheritance by Maxim

Maxim
Sat Feb 12 10:59:33 CST 2005

> Those in doubt can meditate a while over the famous etching
> of M.C. Escher "Water and Sky"
> http://www.worldofescher.com/store/jpgs/P8L.jpg
> and it will become very clear to them, that these are two different worlds.

This is a bit phylosophical question of "shape and its content".

App-level software (databases, webs etc) - usually have not-so-complex (but
often large-amount) content. So, they can go in for making complex shape - and
the shape of any OO language is larger then of C. This complex shape will
simplify their already simpler content.

Now the system software. Often, it has very, very complex content, which can
hardly be simplified by C++ shape. If you add the shape complexity there - the
code will start to be hardly comprehendable and maintainable.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: Inheritance by m

m
Sat Feb 12 14:09:30 CST 2005

Indeed, somtimes it is much harder to do somethings with C++ and objects
then it is to do the same thing with C.

Actualy, very few things that are (or should) be done in kernel mode are
actualy object oriented tasks. It is somtimes usefull to make use of
objects in performing those tasks however - hense the debate.

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:ea$TtQSEFHA.3536@TK2MSFTNGP15.phx.gbl...
> > Those in doubt can meditate a while over the famous etching
> > of M.C. Escher "Water and Sky"
> > http://www.worldofescher.com/store/jpgs/P8L.jpg
> > and it will become very clear to them, that these are two different
worlds.
>
> This is a bit phylosophical question of "shape and its content".
>
> App-level software (databases, webs etc) - usually have not-so-complex
(but
> often large-amount) content. So, they can go in for making complex shape -
and
> the shape of any OO language is larger then of C. This complex shape will
> simplify their already simpler content.
>
> Now the system software. Often, it has very, very complex content, which
can
> hardly be simplified by C++ shape. If you add the shape complexity there -
the
> code will start to be hardly comprehendable and maintainable.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: Inheritance by Mark

Mark
Sun Feb 13 12:55:18 CST 2005

m wrote:
> Indeed, somtimes it is much harder to do somethings with C++ and objects
> then it is to do the same thing with C.
>
> Actualy, very few things that are (or should) be done in kernel mode are
> actualy object oriented tasks. It is somtimes usefull to make use of
> objects in performing those tasks however - hense the debate.
>

The NT kernel has quite a few object oriented abstractions implemented
in C using various home-grown replacements for the natural features of
the C++ compiler. The driver framework of driver objects, device objects
dispatch tables etc. just begs for an object oriented implementation.
Many developers, recognizing the nature of the beast, have put object
oriented wrappers around the C constructs. For example, Microsoft's
Driver Frameworks, Compuware's product, etc. etc.

--

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

Re: Inheritance by Mark

Mark
Sun Feb 13 12:55:37 CST 2005

Don Burn wrote:
> There are a heck of a lot of other problems, such as copy constructors,
> attempted use of STL, mixing exception handling, etc. Yes it can be argued
> that a "good C++ programmer" would know these things, but a lot of people
> think they know more than they do!
>

All of those issues are simply dealt with via FAQ. The 'where does the
compiler put generated code' issue is not in that category.


> C++ in the kernel is fine, for a experienced developer who knows his work
> will only be passed on to other experieced develoers, otherwise it is a
> disaster waiting to happen.
>

Whatever. Just substitute 'C' for 'C++' are you have an equally valid
statement.


--

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

Re: Inheritance by m

m
Sun Feb 13 19:51:55 CST 2005

You are merely corroborating the statement that I just made: very few TASKs
are object oriented, but it is sometimes useful to employ objects to perform
them.



The direct analog of a C++ object, in C, is a structure and a family of
functions that operate on the data - this is the definition of an 'object'.
The family of functions approach can be more flexible, though harder to
comprehend and more verbose, when employed to solve tasks that are
process-flow in essence; since these functions shift the unit of operation
to the thread / stack and can operate on zero or more 'objects'.




I understand that many programmers like to work with objests, but the only
adavantage that C++ presents over C is a symlified synatax for theire use(
pObj->Func versus OBJ_FUNC(pStr))



A conjecture can be tendered that all of these things are equally achievable
in C++, but the relevant issues is not what is possible, but what is better
and easier - and hence should be done.



The direct analogy is something like: When putting a square peg in a round
hole, it is possible to use one with the same dimension as the hole, but it
is easier to use a smaller one.



I hope this makes everything as clear as mud ;)





"Mark Roddy" <markr@hollistech.com> wrote in message
news:e#KpQ2fEFHA.1296@TK2MSFTNGP10.phx.gbl...
> m wrote:
> > Indeed, somtimes it is much harder to do somethings with C++ and objects
> > then it is to do the same thing with C.
> >
> > Actualy, very few things that are (or should) be done in kernel mode are
> > actualy object oriented tasks. It is somtimes usefull to make use of
> > objects in performing those tasks however - hense the debate.
> >
>
> The NT kernel has quite a few object oriented abstractions implemented
> in C using various home-grown replacements for the natural features of
> the C++ compiler. The driver framework of driver objects, device objects
> dispatch tables etc. just begs for an object oriented implementation.
> Many developers, recognizing the nature of the beast, have put object
> oriented wrappers around the C constructs. For example, Microsoft's
> Driver Frameworks, Compuware's product, etc. etc.
>
> --
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com



Re: Inheritance by 440gtx

440gtx
Mon Feb 14 02:14:55 CST 2005

> I understand that many programmers like to work with objests, but the
> only adavantage that C++ presents over C is a symlified synatax for
> theire use(> pObj->Func versus OBJ_FUNC(pStr))

Only advantage? Syntax is just one way objects in C++ are better.
Scoping and inheritence help developers make more robust and elegant
code. You also miss many clever syntax gains by operators such as say
creating an interlocked data type. For instance:

The way we must do this in C: InterlockedIncrement(&x);
In C++ you could do it like this too: ++x;

It seems a common misconception to equate C++ with objects. C++ is C
language with new additional language features at your service. You
don't have to use any of them if you don't want. You can write C style
code if you want. There are bountiful new capabilities besides objects
like default parameters, reference pointers, and function overloading.
Again, all optional and up to you on if/how to use them.


Re: Inheritance by m

m
Mon Feb 14 12:41:12 CST 2005



I don't want to get into a 'he said / she said' but...



Inheritance is fun to play with but can be done better with #define

Scoping exists natively in C - just the only level of scope is file ( I have
never needed more than this)



You are correct; there are a number of clever things that C++ allows you to
do.



I don't think it is a misconception to associate the primary difference
between two languages with the difference. Yes there are some other useful
things, but just because your toy has 10 buttons and mine only has 3 doesn't
necessarily mean that yours is better for the task.



Elegance is a matter of opinion. Certainly C++ constructs require less
typing; but as for being more elegant?




<440gtx@email.com> wrote in message
news:1108368895.698169.275710@c13g2000cwb.googlegroups.com...
> > I understand that many programmers like to work with objests, but the
> > only adavantage that C++ presents over C is a symlified synatax for
> > theire use(> pObj->Func versus OBJ_FUNC(pStr))
>
> Only advantage? Syntax is just one way objects in C++ are better.
> Scoping and inheritence help developers make more robust and elegant
> code. You also miss many clever syntax gains by operators such as say
> creating an interlocked data type. For instance:
>
> The way we must do this in C: InterlockedIncrement(&x);
> In C++ you could do it like this too: ++x;
>
> It seems a common misconception to equate C++ with objects. C++ is C
> language with new additional language features at your service. You
> don't have to use any of them if you don't want. You can write C style
> code if you want. There are bountiful new capabilities besides objects
> like default parameters, reference pointers, and function overloading.
> Again, all optional and up to you on if/how to use them.
>



Re: Inheritance by heinz

heinz
Tue Feb 15 03:36:44 CST 2005

If you want a clear picture of several benefits of C++ in a driver,
check the below white paper. It shows how inheritence and scoping yield
more elegant, type safe dispatch routines.

http://www.perisoft.net/engineer/cpp.htm

For me, one well used part of C++ is eliminating callback functions
that take a void *context parameter. Virtual functions do that job
elegantly, concisely, and with type safety and no casting.

You seem to be kind of set in your ways. I think of C++ as basically
being able to reach into a bigger toolbox. An expert craftsman will
exploit the new tools to gain a better result. Language tools can be
used improperly, but that's true even in C (eg: refusing to use while
statements because goto statements can suffice).


Re: Inheritance by Maxim

Maxim
Tue Feb 15 07:45:36 CST 2005

> more elegant, type safe dispatch routines.

Dispatch routine takes the arguments of PDEVICE_OBJECT and PIRP. What more type
safety do you want?

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: Inheritance by Maxim

Maxim
Tue Feb 15 07:44:02 CST 2005

> Only advantage? Syntax is just one way objects in C++ are better.

No. The code is lesser readable. Just imagine:

// some header
class MyClass
{
void get(....);
};

// some CPP file.

MyClass myObj;

// some second CPP file.

myObj.get();

Now go and guess what "get" is called here. First, you will need to find
"myObj" declaration, and then the declaration of its class. Two steps. Now the
OO-less style:

MyClassGet(&myObj);

- and then just "Find In Files" (or GNU grep) for "MyClassGet".

The OO syntax of method calls is justified for polymorphyc method calls only.

> Scoping

Scoping is evil. See the above sample.

Having 10 "get" calls from 10 namespaces decreases readability. Having explicit
lexical prefixes like MyObjectGet(), MyThingGet() etc - increases it. Reading
the code becomes the more usable task.

>and inheritence help developers make more

Inheritance is evil in vast majority of cases. Imagine class B, and its derived
D1, D2 and D3. Now imagine you have a bug looking like in D1. You do a
bugfixing, and the bug appears to be - in B. OK, you fix B. This suddenly
breaks D2 and D3 :)

The thing is that the derived classes were relying on undocumented and
un-described implementation details of the base class. Sorry, but code
copy/paste would be better in this case :)

More so, the modern OO theoretical paradigm makes some new (and more sane)
suggestions. They introduce the notion of "links" between modules, and the
notion of "weaking links" or "hardening" them. The goal is - to weaken links,
since this really means more robust, more elegant and more readable and
maintainable code. "Divide and conquer" :) Decomposition.

For instance, the classic encapsulation is now treated as "weaking links" -
weaking by making them described, documented, predictable and narrowing their
possible set.

Then our "beloved" implementation inheritance. It is the _most hard kind of
links between the 2 modules you can have_, for instance, you are now dependent
on lots of undocumented implementation details of the base class. Links of such
hardness are nearly impossible to do in C.

So, this is just plain evil in majority of cases, unless you will spend a lot
of brain time inventing the whole inheritance tree, and for many tasks this
inheritance tree will only spoil and not help.

Implementation inheritance is not decomposition - it creates a very hard kind
of link and not weakens the links (which decomposition must do). It is nothing
more then a code reuse for lazies, and in many cases copy/paste is more robust
(yes, I know the drawback of copy/paste).

For now, modern OO suggests only _interface inheritance_ (and polymorphyc use
of interfaces) which is for sure good.

Looks like the OO theory is going right way. C++ is surely not. It is just
overloaded with unstructured mix (pile?) of all kinds of features, often from
contradicting programming styles (like RTTI, which is evil due to suggesting
non-polymorphic programming styles).

>robust and elegant

Robust? See the above samples, on how C++ use decreases robustness.

> code. You also miss many clever syntax gains

Yes, it's a well-known fact, but why is it good? Lesser typing? with harder
comprehending? we're moving to "write-only languages" like Perl, who has lots
of syntax sugar, too lot for even the author to comprehend the own code in
several months.

> The way we must do this in C: InterlockedIncrement(&x);
> In C++ you could do it like this too: ++x;

I feel real aversion to such ideas. Really. Implementing such a routine will
make it impossible to distinguish interlocked increment from non-interlocked
one, and will - with a good change - make all increments interlocked. Goodbye
performance.

Smaller amount of characters in the statement does NOT mean good readability.

> It seems a common misconception to equate C++ with objects. C++ is C
> language with new additional language features at your service.

Surely. C++ does not implement proper OO in pure OO style, BTW :). C++ has
features which decrease readability and maintainability. C++ has features like
RTTI which just breaks the OO idea.

> code if you want. There are bountiful new capabilities besides objects
> like default parameters,

Why this is good? This is overloading (automatically). You have 2 entities with
the same name of get(). How is it good? Lesser typing? Sorry, but typing is
around 0.1% of development cost.

>reference pointers

They are evil. Imagine:

void MyFunc(int& c);

and later

MyFunc(i);

The programmer will be VERY much annoyed that the value of "i" was changed by
MyFunc call. Very much. Now the C style:

void MyFunc(int* C);

MyFunc(&i);

You see - the "&" char explicitly tells the reader - "note! this is passed by
reference!".

C++ references have only one valid use - parameters for copy constructors and
overloaded operators. In any other case, just replace them with C-style
pointers, and you will have a major gain in code readability without any losses
(references are pointers at machine level anyway).

>, and function overloading.

OK, let's overload the bitwise shift as file output. The most stupid thing in
whole C++ maybe.

Then let's add overloaded operators like "+" to our classes without providing
their natural semantics, for instance, let's add "+" which will change the
internal state of one of the terms. :) Easy :).

And very, very much annoying when reading and maintaing the code. With C, you
would have the speaking meaningful names instead.

Well, "operator +" is not this evil. At least it requires "+" token to appear
in code to be called under the hood. "operator T" is not such. It requires _no
code at all_ to be called under the hood.

With C, if you see the assignment, you're sure that the types are the same.
With C++, you need to understand the exact type (which can be a complex class
or - worse - template) of the right side, and then go to appropriate header and
find "operator T" for the left side in it.

> Again, all optional and up to you on if/how to use them.

Yes. C++ is usable, if you will ban a lot of features from it by administrative
order in the team :) Some features are evil, some are evil in all cases except
1 special one, and so on.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: Inheritance by cristalink

cristalink
Tue Feb 15 12:57:01 CST 2005

I think it's a waste of time trying to convince ? people of C++ advantages.
They just don't understand C++ and cannot use it properly. They possibly
tried but failed. For some reason, many of such people are kernel
programmers. It's hard to blame them, C++ is definitely not for everyone.

Once I was working for a big company that produced swtitches and routers and
heard the following words from a senior developer - "we don't need C++ since
there are no objects in the router code, well, may be two of three". I would
find thousands of objects there.
--
http://www.firestreamer.com - NTBackup to DVD and DV


"heinz" <heinz_baer@my-deja.com> wrote in message
news:1108460203.980170.70150@l41g2000cwc.googlegroups.com...
> If you want a clear picture of several benefits of C++ in a driver,
> check the below white paper. It shows how inheritence and scoping yield
> more elegant, type safe dispatch routines.
>
> http://www.perisoft.net/engineer/cpp.htm
>
> For me, one well used part of C++ is eliminating callback functions
> that take a void *context parameter. Virtual functions do that job
> elegantly, concisely, and with type safety and no casting.
>
> You seem to be kind of set in your ways. I think of C++ as basically
> being able to reach into a bigger toolbox. An expert craftsman will
> exploit the new tools to gain a better result. Language tools can be
> used improperly, but that's true even in C (eg: refusing to use while
> statements because goto statements can suffice).
>



Re: Inheritance by cristalink

cristalink
Tue Feb 15 12:59:07 CST 2005

I meant to say "convince C people of C++ advantages"


"cristalink" <cristalink@nospam.nospam> wrote in message
news:egqHjA5EFHA.3636@TK2MSFTNGP09.phx.gbl...
>I think it's a waste of time trying to convince ? people of C++ advantages.
>They just don't understand C++ and cannot use it properly. They possibly
>tried but failed. For some reason, many of such people are kernel
>programmers. It's hard to blame them, C++ is definitely not for everyone.
>
> Once I was working for a big company that produced swtitches and routers
> and heard the following words from a senior developer - "we don't need C++
> since there are no objects in the router code, well, may be two of three".
> I would find thousands of objects there.
> --
> http://www.firestreamer.com - NTBackup to DVD and DV
>
>
> "heinz" <heinz_baer@my-deja.com> wrote in message
> news:1108460203.980170.70150@l41g2000cwc.googlegroups.com...
>> If you want a clear picture of several benefits of C++ in a driver,
>> check the below white paper. It shows how inheritence and scoping yield
>> more elegant, type safe dispatch routines.
>>
>> http://www.perisoft.net/engineer/cpp.htm
>>
>> For me, one well used part of C++ is eliminating callback functions
>> that take a void *context parameter. Virtual functions do that job
>> elegantly, concisely, and with type safety and no casting.
>>
>> You seem to be kind of set in your ways. I think of C++ as basically
>> being able to reach into a bigger toolbox. An expert craftsman will
>> exploit the new tools to gain a better result. Language tools can be
>> used improperly, but that's true even in C (eg: refusing to use while
>> statements because goto statements can suffice).
>>
>
>



Re: Inheritance by Don

Don
Tue Feb 15 13:13:38 CST 2005

Well, I have used C++ extensively, was on the C++ Standards Committee, and
have been part of a C++ compiler team. But knowing what I know, and the
number of things that the compiler can do for you (that you don't expect) in
C++ without it being obvious, I would never use C++ in the kernel. I have
heard that some of the Microsoft groups that use C++ in the kernel do a
manual review of the generated assembler to be sure that no surprises show
up. Personally, doing that level of review means unless someone can show a
huge justification for C++, I can't afford the overhead.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



"cristalink" <cristalink@nospam.nospam> wrote in message
news:egqHjA5EFHA.3636@TK2MSFTNGP09.phx.gbl...
>I think it's a waste of time trying to convince ? people of C++ advantages.
>They just don't understand C++ and cannot use it properly. They possibly
>tried but failed. For some reason, many of such people are kernel
>programmers. It's hard to blame them, C++ is definitely not for everyone.
>
> Once I was working for a big company that produced swtitches and routers
> and heard the following words from a senior developer - "we don't need C++
> since there are no objects in the router code, well, may be two of three".
> I would find thousands of objects there.
> --
> http://www.firestreamer.com - NTBackup to DVD and DV
>
>



Re: Inheritance by cristalink

cristalink
Tue Feb 15 15:12:15 CST 2005

> Inheritance is evil in vast majority of cases. Imagine class B, and its
> derived
> D1, D2 and D3. Now imagine you have a bug looking like in D1. You do a
> bugfixing, and the bug appears to be - in B. OK, you fix B. This suddenly
> breaks D2 and D3 :)

This is a perfect example of how C++ code should NOT be written. You would
hardly encounter such a problem in properly designed C++ code.

> The thing is that the derived classes were relying on undocumented and
> un-described implementation details of the base class.

I wonder what would happen if your C driver relied on undocumented and
un-described kernel API. Of course any code should use a well defined and
documented base.

--
http://www.firestreamer.com - NTBackup to DVD and DV


"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:%234PmUR2EFHA.3636@TK2MSFTNGP09.phx.gbl...
>> Only advantage? Syntax is just one way objects in C++ are better.
>
> No. The code is lesser readable. Just imagine:
>
> // some header
> class MyClass
> {
> void get(....);
> };
>
> // some CPP file.
>
> MyClass myObj;
>
> // some second CPP file.
>
> myObj.get();
>
> Now go and guess what "get" is called here. First, you will need to find
> "myObj" declaration, and then the declaration of its class. Two steps. Now
> the
> OO-less style:
>
> MyClassGet(&myObj);
>
> - and then just "Find In Files" (or GNU grep) for "MyClassGet".
>
> The OO syntax of method calls is justified for polymorphyc method calls
> only.
>
>> Scoping
>
> Scoping is evil. See the above sample.
>
> Having 10 "get" calls from 10 namespaces decreases readability. Having
> explicit
> lexical prefixes like MyObjectGet(), MyThingGet() etc - increases it.
> Reading
> the code becomes the more usable task.
>
>>and inheritence help developers make more
>
> Inheritance is evil in vast majority of cases. Imagine class B, and its
> derived
> D1, D2 and D3. Now imagine you have a bug looking like in D1. You do a
> bugfixing, and the bug appears to be - in B. OK, you fix B. This suddenly
> breaks D2 and D3 :)
>
> The thing is that the derived classes were relying on undocumented and
> un-described implementation details of the base class. Sorry, but code
> copy/paste would be better in this case :)
>
> More so, the modern OO theoretical paradigm makes some new (and more sane)
> suggestions. They introduce the notion of "links" between modules, and the
> notion of "weaking links" or "hardening" them. The goal is - to weaken
> links,
> since this really means more robust, more elegant and more readable and
> maintainable code. "Divide and conquer" :) Decomposition.
>
> For instance, the classic encapsulation is now treated as "weaking
> links" -
> weaking by making them described, documented, predictable and narrowing
> their
> possible set.
>
> Then our "beloved" implementation inheritance. It is the _most hard kind
> of
> links between the 2 modules you can have_, for instance, you are now
> dependent
> on lots of undocumented implementation details of the base class. Links of
> such
> hardness are nearly impossible to do in C.
>
> So, this is just plain evil in majority of cases, unless you will spend a
> lot
> of brain time inventing the whole inheritance tree, and for many tasks
> this
> inheritance tree will only spoil and not help.
>
> Implementation inheritance is not decomposition - it creates a very hard
> kind
> of link and not weakens the links (which decomposition must do). It is
> nothing
> more then a code reuse for lazies, and in many cases copy/paste is more
> robust
> (yes, I know the drawback of copy/paste).
>
> For now, modern OO suggests only _interface inheritance_ (and polymorphyc
> use
> of interfaces) which is for sure good.
>
> Looks like the OO theory is going right way. C++ is surely not. It is just
> overloaded with unstructured mix (pile?) of all kinds of features, often
> from
> contradicting programming styles (like RTTI, which is evil due to
> suggesting
> non-polymorphic programming styles).
>
>>robust and elegant
>
> Robust? See the above samples, on how C++ use decreases robustness.
>
>> code. You also miss many clever syntax gains
>
> Yes, it's a well-known fact, but why is it good? Lesser typing? with
> harder
> comprehending? we're moving to "write-only languages" like Perl, who has
> lots
> of syntax sugar, too lot for even the author to comprehend the own code in
> several months.
>
>> The way we must do this in C: InterlockedIncrement(&x);
>> In C++ you could do it like this too: ++x;
>
> I feel real aversion to such ideas. Really. Implementing such a routine
> will
> make it impossible to distinguish interlocked increment from
> non-interlocked
> one, and will - with a good change - make all increments interlocked.
> Goodbye
> performance.
>
> Smaller amount of characters in the statement does NOT mean good
> readability.
>
>> It seems a common misconception to equate C++ with objects. C++ is C
>> language with new additional language features at your service.
>
> Surely. C++ does not implement proper OO in pure OO style, BTW :). C++ has
> features which decrease readability and maintainability. C++ has features
> like
> RTTI which just breaks the OO idea.
>
>> code if you want. There are bountiful new capabilities besides objects
>> like default parameters,
>
> Why this is good? This is overloading (automatically). You have 2 entities
> with
> the same name of get(). How is it good? Lesser typing? Sorry, but typing
> is
> around 0.1% of development cost.
>
>>reference pointers
>
> They are evil. Imagine:
>
> void MyFunc(int& c);
>
> and later
>
> MyFunc(i);
>
> The programmer will be VERY much annoyed that the value of "i" was changed
> by
> MyFunc call. Very much. Now the C style:
>
> void MyFunc(int* C);
>
> MyFunc(&i);
>
> You see - the "&" char explicitly tells the reader - "note! this is passed
> by
> reference!".
>
> C++ references have only one valid use - parameters for copy constructors
> and
> overloaded operators. In any other case, just replace them with C-style
> pointers, and you will have a major gain in code readability without any
> losses
> (references are pointers at machine level anyway).
>
>>, and function overloading.
>
> OK, let's overload the bitwise shift as file output. The most stupid thing
> in
> whole C++ maybe.
>
> Then let's add overloaded operators like "+" to our classes without
> providing
> their natural semantics, for instance, let's add "+" which will change the
> internal state of one of the terms. :) Easy :).
>
> And very, very much annoying when reading and maintaing the code. With C,
> you
> would have the speaking meaningful names instead.
>
> Well, "operator +" is not this evil. At least it requires "+" token to
> appear
> in code to be called under the hood. "operator T" is not such. It requires
> _no
> code at all_ to be called under the hood.
>
> With C, if you see the assignment, you're sure that the types are the
> same.
> With C++, you need to understand the exact type (which can be a complex
> class
> or - worse - template) of the right side, and then go to appropriate
> header and
> find "operator T" for the left side in it.
>
>> Again, all optional and up to you on if/how to use them.
>
> Yes. C++ is usable, if you will ban a lot of features from it by
> administrative
> order in the team :) Some features are evil, some are evil in all cases
> except
> 1 special one, and so on.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: Inheritance by Philip

Philip
Tue Feb 15 15:46:07 CST 2005

"Don Burn" <burn@stopspam.acm.org> wrote in message
news:CRrQd.6487$wP1.175@fe03.lga...
> Well, I have used C++ extensively, was on the C++ Standards Committee, and
> have been part of a C++ compiler team. But knowing what I know, and the
> number of things that the compiler can do for you (that you don't expect)
in
> C++ without it being obvious, I would never use C++ in the kernel. I have
> heard that some of the Microsoft groups that use C++ in the kernel do a
> manual review of the generated assembler to be sure that no surprises show
> up. Personally, doing that level of review means unless someone can show
a
> huge justification for C++, I can't afford the overhead.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
[snip]

I'm just curious, what does MS expect portcls audio developers to do, as C++
is required in these cases? Check assembly code each time they recompile?
Check out the DDK MSVAD audio examples, which use C++, *and* inheritance
(C:\WINDDK\3790.1433\src\wdm\audio\msvad on my machine).

Are these samples unsafe? Or are these practices, as exemplified in these
samples, the limit of C++ safe usage? I'm not advocating anything, simply
wondering how to reconcile the MS white paper, and these portcls audio
driver realities.

Philip Lukidis



Re: Inheritance by Don

Don
Tue Feb 15 15:59:47 CST 2005

Phillip,

This is my interpretation, but I believe just like the division of
opinion that this discussion has had, that the Microsoft development teams
have the same different thoughts on the danges/advantages of C++. I haven't
worked in kernel streaming so I can't comment on the audio samples, but in
general I would take the approach of minimalist C++ with as few features as
possible.

Note: I have used the .cpp extension to build drivers, but they have
been pure C in implementation. Using C++ added some checks, but nowadays I
find I can get the same effect by using /WALL /W4 (with some #pramga
statements to fix the ntddk.h problems).



--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply


"Philip Lukidis" <pleasedontemail@nowehere.net> wrote in message
news:O1jyCf6EFHA.2232@TK2MSFTNGP14.phx.gbl...
> "Don Burn" <burn@stopspam.acm.org> wrote in message
> news:CRrQd.6487$wP1.175@fe03.lga...
>> Well, I have used C++ extensively, was on the C++ Standards Committee,
>> and
>> have been part of a C++ compiler team. But knowing what I know, and the
>> number of things that the compiler can do for you (that you don't expect)
> in
>> C++ without it being obvious, I would never use C++ in the kernel. I
>> have
>> heard that some of the Microsoft groups that use C++ in the kernel do a
>> manual review of the generated assembler to be sure that no surprises
>> show
>> up. Personally, doing that level of review means unless someone can show
> a
>> huge justification for C++, I can't afford the overhead.
>>
>>
>> --
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> Remove StopSpam from the email to reply
>>
> [snip]
>
> I'm just curious, what does MS expect portcls audio developers to do, as
> C++
> is required in these cases? Check assembly code each time they recompile?
> Check out the DDK MSVAD audio examples, which use C++, *and* inheritance
> (C:\WINDDK\3790.1433\src\wdm\audio\msvad on my machine).
>
> Are these samples unsafe? Or are these practices, as exemplified in these
> samples, the limit of C++ safe usage? I'm not advocating anything, simply
> wondering how to reconcile the MS white paper, and these portcls audio
> driver realities.
>
> Philip Lukidis
>
>



Re: Inheritance by Philip

Philip
Tue Feb 15 16:43:06 CST 2005

"Don Burn" <burn@stopspam.acm.org> wrote in message
news:nhuQd.10695$o66.1268@fe06.lga...
> Phillip,
>
> This is my interpretation, but I believe just like the division of
> opinion that this discussion has had, that the Microsoft development teams
> have the same different thoughts on the danges/advantages of C++. I
haven't
> worked in kernel streaming so I can't comment on the audio samples, but in
> general I would take the approach of minimalist C++ with as few features
as
> possible.
>
> Note: I have used the .cpp extension to build drivers, but they
have
> been pure C in implementation. Using C++ added some checks, but nowadays
I
> find I can get the same effect by using /WALL /W4 (with some #pramga
> statements to fix the ntddk.h problems).
>
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
[snip]
I suppose that given this hesitation from within MS, keeping C++ to a
minimum would be the safe bet. Too bad at least two of the drivers which
I'm working on use DriverStudio, and with related products on the way,
probably more, given time constraints. Hardly the most prudent course, I
must admit, but so far I haven't found any C++ issue. In any case, using
DriverStudio was never for me a substitute for careful DDK reading and WDM
knowledge.

Oops, I did once find a C++ related issue, in Windows 98SE *only*, where
some code was unexpectedly put into the INIT segment. I solved that by
simply not using an INIT segment *ever* ( and I haven't worked on Win98SE/ME
since, hope *that* holds). If some code is placed in unexpected segments, I
hope to catch it in early testing using driver verifier (code coverage would
be called for).

Philip Lukidis

PS: it wasn't my decision to use DS in either case, but switching now would
be tough to justify.






Re: Inheritance by heinz

heinz
Tue Feb 15 21:20:20 CST 2005

> Dispatch routine takes the arguments of PDEVICE_OBJECT and PIRP.
> What more type safety do you want?

Getting at the DeviceExtension from the dispatch routine requires a
cast and that creates room for error because typically drivers work
with different types of device objects and yet have just one all
encompassing device extension structure blob. So the challenge is
exercising care to access only those fields pertinent to the device
object being worked with. The link up from your post shows how this
problem can be eliminated using C++. In the example, the PDO dispatch
routine cannot accidentally access FDO data and vice versa.


Re: Inheritance by Maxim

Maxim
Wed Feb 16 11:32:46 CST 2005

> Getting at the DeviceExtension from the dispatch routine requires a
> cast

Oh yes! 1 cast for 100 lines of code?

>and that creates room for error

Very, very small room. Very, very easy to find.

In real world, the bugs in drivers are not there :) I would even say - never
there