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

  • From: Girish Pattabiraman <girish.pattabiraman@xxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Tue, 1 Mar 2011 21:55:19 -0800

Larry and Tim,

I appreciate your input, if I had an option, I would definitely write my
driver in C and avoid all the pitfalls.
Unfortunately Audio drivers are based on PortCls in which I have no option
but to implement the given C++ interfaces.

Tom, I have a JTAG attached and I've configured my WinDbg properly to handle
all the crash dumps and analysis, but what I'm worried about are the hidden
dangers expressed in the article about C++ which might show up randomly.

Specifically:
Is there anyway that I can write audio driver in C?

Our audio hardware is pretty complex involving a lot of post processing and
stuff, there is no way that I can sit and go through the compiler generated
assembly as suggested in the article.

Is there a tool like DriverVerifer which can warn or catch the bugs.

Regards,
Girish

On Tue, Mar 1, 2011 at 5:43 PM, Tom Duffy <tduffy@xxxxxxxxxx> wrote:

>
> I have written kernel level code (not specifically a driver)
> that used C++ in the past, using mostly just classes to encapsulate
> some functionality in a clean API.
> Even simple things such as class static data initialization doesn't
> occur, so I had to add manual "init" methods to several places.
>
> If you get anything wrong, the machine rewards you with a BSOD,
> so you'd better have a tool such as SoftICE in order to debug it.
>
> Tom.
>
>
> Larry Osterman wrote:
>
>> 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.
>>
>> Larry
>>
>> *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 -
>> http://msdn.microsoft.com/en-us/windows/hardware/gg487420.aspx
>>
>> 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?
>>
>> Regards,
>> Girish
>>
>> --
>> "Motive of LIFE: It is not death that I wish to avoid but life which I
>> wish to live." - Ayn Rand
>>
>>
> NOTICE: This electronic mail message and its contents, including any
> attachments hereto (collectively, "this e-mail"), is hereby designated as
> "confidential and proprietary." This e-mail may be viewed and used only by
> the person to whom it has been sent and his/her employer solely for the
> express purpose for which it has been disclosed and only in accordance with
> any confidentiality or non-disclosure (or similar) agreement between TEAC
> Corporation or its affiliates and said employer, and may not be disclosed to
> any other person or entity.
>
> ******************
>
> WDMAUDIODEV addresses:
> Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
> Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
> Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
> Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx
>
> URL to WDMAUDIODEV page:
> http://www.wdmaudiodev.com/
>
>


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

Other related posts: