[wdmaudiodev] Re: To C++ or not to C++

  • From: Larry Osterman <Larry.Osterman@xxxxxxxxxxxxx>
  • To: "wdmaudiodev@xxxxxxxxxxxxx" <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Wed, 2 Mar 2011 01:34:09 +0000

The set of C++ constructs that don't work from kernel mode is significantly 
larger than the set of C++ constructs that *do* work.  All sorts of constructs 
can cause issues for kernel code.

As the article says: "The use of the C++ compiler as a "super-C" is typically 
expected to work, but such use of the compiler is at the developers own risk".  
If you don't take advantage of any of the challenging language features of C++ 
(including but not limited to: templates, the standard runtime library, 
operator overloading, and exceptions), then you have a decent chance of being 
able to successfully write a driver in C++.   The only way to really ensure 
that things work is to manually inspect the code generated by the compiler to 
make sure that illegal constructs aren't accidentally being pulled in.

If you write your driver in C, you're almost guaranteed to be able to build a 
driver that works because there are very few C constructs that aren't supported 
in the driver.


From: wdmaudiodev-bounce@xxxxxxxxxxxxx 
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx] On Behalf Of Girish Pattabiraman
Sent: Tuesday, March 01, 2011 5:08 PM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] To C++ or not to C++

MSDN has this article about risks of using C++ in drivers - 

But PortCls drivers, especially audio drivers are C++ by default.

Why have they taken such a cowardly approach in the article?
Either they should declare explicitly that C++ is not allowed, or they should 
provide full support for C++.

I don't like the words "might", "maybe", etc. in documentation. Computer 
science is an exact science in which everything should be clearly defined.

The author mentions reading the output of the compiler (assembly) carefully, is 
he really being serious about it??
Does he really expect us to go through assembly output of the compiler?
I'm not super-human and cannot (infact refuse) to go through compiler generated 
assembly of everything I have written.

Has anyone ever encountered a crash due to using C++ in WDM drivers?


"Motive of LIFE: It is not death that I wish to avoid but life which I wish to 
live." - Ayn Rand

Other related posts: