Mixing C and C++ files in a driver project.

> As long as all the source file contents are C++ rather than C, of course

Why??? Contents of .cpp file can be written in pure C - there is no problem here whatsoever. However, the opposite is not true - if you do something C+±specific (for example, declare a variable in the middle of a function) in a .c file, you have no chance to compile it without changing file extension to .cpp…

Anton Bassov.

The last time I looked there is an override option for the Microsoft
compilers that allow .c files to be processed as .cpp. That is another way
to do it, but it is a personal preference if you want to do it that way.

wrote in message news:xxxxx@ntdev…
>> As long as all the source file contents are C++ rather than C, of course
>
> Why??? Contents of .cpp file can be written in pure C - there is no
> problem here whatsoever. However, the opposite is not true - if you do
> something C+±specific (for example, declare a variable in the middle of a
> function) in a .c file, you have no chance to compile it without changing
> file extension to .cpp…
>
> Anton Bassov.
>

Don… you seem awfully wound-up. Bad week?

Did you just call me both an idiot and stupid, or did I mis-read that? Cuz that wouldn’t be very nice.

Lest you doubt, let me repeat: Here at OSR, our long-standing practice is to write standard C in files with .CPP file types. We strongly urge our students, and all newbies, to follow this practice. This is regardless of whether Don once found a bug in “a sample in an expensive OSR toolkit” – Gee, I guess we had a bug once. I’m surprised. Not. Zzzzzz…

If you don’t use it, I’m not surprised you haven’t found a bug with it.

I, personally, have never – not ONCE – FAILED to find a MEANINGFUL bug when converting a project that uses .C files types to using .CPP file types.

I just don’t get the histrionics, Don. Maybe I’m both stooopid AND an idiot, but you haven’t indicated what your OBJECTION is to using standard C in files with .CPP file types. Now, recall that I think C++ is an evil language that’s in-league with the devil, so you’re not likely to find any classes or polymorphism, or any of that shit in any of my drivers. So, what’s your problem?

Peter
OSR

Peter,

My biggest complaint with “.cpp” is what I call “C++ creep”. It is
amazing the number of times that people provide a .cpp file and say don’t
worry it is pure “C”, except for the fact that it won’t compile with the C
compiler at all if you rename it .c! Now, when someone hands you a big
project and says evaluate this for us including, running through all the
latest Microsoft tools, including SDV that “C++ creep” becomes a big
problem. While I have not had good luck with really finding bugs with SDV,
it has huge potential and AFAIK still does not support C++. Also there are
other tools out there that can have problems digesting things other than C.
The result of “C++ creep” is that you have to modify the code with the
potential for adding bugs, just to use tools with the goal of finding bugs.

I don’t use C++ normally, but I do check code with it useing /TP which
I documented in my
http://download.microsoft.com/download/5/D/6/5D6EAF2B-7DDF-476B-93DC-7CF0072878E6/DrvDev_Intro.doc
three years ago. This treats C files as CPP filkes but since it can be
added as removed easily it means that you can use C++ as a better C without
getting “C++ creep”. I particuraily do this on code I inherit, and I have
never found a single problem usig C++ except ones that were also found with
the other tools.

I did not mean to imply you or anyone at OSR is an idiot, and yes it
has been a horrendous week.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntdev…
>


>
> Don… you seem awfully wound-up. Bad week?
>
> Did you just call me both an idiot and stupid, or did I mis-read that?
> Cuz that wouldn’t be very nice.
>
> Lest you doubt, let me repeat: Here at OSR, our long-standing practice is
> to write standard C in files with .CPP file types. We strongly urge our
> students, and all newbies, to follow this practice. This is regardless of
> whether Don once found a bug in “a sample in an expensive OSR toolkit” –
> Gee, I guess we had a bug once. I’m surprised. Not. Zzzzzz…
>
>


>
> If you don’t use it, I’m not surprised you haven’t found a bug with it.
>
> I, personally, have never – not ONCE – FAILED to find a MEANINGFUL bug
> when converting a project that uses .C files types to using .CPP file
> types.
>
> I just don’t get the histrionics, Don. Maybe I’m both stooopid AND an
> idiot, but you haven’t indicated what your OBJECTION is to using standard
> C in files with .CPP file types. Now, recall that I think C++ is an evil
> language that’s in-league with the devil, so you’re not likely to find any
> classes or polymorphism, or any of that shit in any of my drivers. So,
> what’s your problem?
>
>
> Peter
> OSR
>
>

Well, Don… “You might accidentally write some C++” doesn’t sound like very convincing argument to me. You know, if I throw-in an inline declaration or two I don’t feel like either I, or my project, is going to hell for it. If that’s the worst of my engineering sins, I figure I may not be canonized, but I’m doing pretty well. I wasn’t real far along on that canonization route anyways.

As far as what I might ACCIDENTALLY do in my driver, well, I figure there are a lot of things more serious for me to worry about than maybe some “//” comments finding their way into my code, you know… like accidentally screwing up my code with an implicit cast.

And while I really LIKE the members of the SDV team (devs and PMs both… I really do) and appreciate both the enthusiasm they bring to their product and their talent, I’m sorry to say that I have yet to find a bug using SDV (even when I’ve tried to do so intentionally), so I’ve stopped using it. Lots of things have “huge potential” – doesn’t mean I want them in my arsenal of tools… today. Tomorrow, heck, who knows? Maybe we’ll be writing drivers in user mode, and using C#. And, while it doesn’t matter, I’m almost sure that SDV now supports .CPP file types.

As to “other tools out there that can have problems digesting things other than C”, well… I don’t know what they are, I don’t use them, and thus won’t worry about them.

So, let’s see, your argument, though ad-hominem and carried out at a high volume, seems to come down to the following two technical points:

a) SDV, which doesn’t really find any problems, and some tools unnamed which we don’t know, won’t work with C++ so we’ll have to modify the our code to use them. Simple fix to that: Don’t use those tools.

b) If you name your file .CPP, you might accidentally write some C++ and you’re whole project will be in the shitter. Like you’re going to wake up one day and your project will be magically filled with multiple inheritance, functions that differ only by a single parameter, or abstract base classes or something? So, your argument is “there are features of C++ that are evil in driver projects”… and I agree with that argument. Simple fix: Don’t do these things in your drivers.

Sounds pretty simple to me. And hardly warrants the histrionics, you know??

Peter
OSR
Apparently “stupid IDIOT for naming his files .CPP”

Peter,

Peter
OSR
Apparently “stupid IDIOT for naming his files .CPP”

Welcome to our community of Linux developers, AV vendors, university professors and everyone else whom Mr. Burn happens to be a low opinion of. As I can see, you have managed to join our ranks effortlessly - no criticism of either KMD or MSFT, no suggestions that Linux may be somehow better than Windows, no statements saying that some tasks just cannot get achieved without hooking under Windows, nothing at all…

Anton Bassov

Don,

It is amazing the number of times that people provide a .cpp file and say don’t worry it is pure “C”, except for > the fact that it won’t compile with the C compiler at all if you rename it .c!

The solution is really simple. Name file with .c extension and compile it. If everything is OK, rename it to .cpp and compile it again, so that if there is some type mismatch, compiler will catch it (it is better to specify “treat warning as errors” option). What Peter speaks about is just the additional type safety net that comes at no price at all - is it so terribly difficult to change file extension and compile it twice, rather than once??? I really have no idea what you are arguing about…

Anton Bassov

xxxxx@hotmail.com wrote:
[… discussing “just rename the C files to .cpp”]

> As long as all the source file contents are C++ rather than C, of course

Why??? Contents of .cpp file can be written in pure C - there is no
problem here whatsoever. However, the opposite is not true - if you do
something C+±specific (for example, declare a variable in the middle of
a function) in a .c file, you have no chance to compile it without
changing file extension to .cpp…

If they’re written in the subset of C which has the same meaning in both
C and C++, then you’re fine; otherwise you’re not.

In most corporate settings where you have developers hired, fired, laid off,
transferred, and quit, it is very difficult to maintain control over coding
habits. There are standards that vary from company to company and
department to department and also developer to developer. If you name a
file with the ‘cpp’ extension, it is very easy for someone to add something
such as local variables just before their use and slip away from the rule of
no C++ features in the code. If you keep the extension as ‘c’ then you
can’t do that without starting a new block. I think I like the idea of
using the parameter in the sources file to treat all ‘c’ files as ‘cpp’, but
that of course means you need to do the compile twice to catch code that
violates the rules of C. I think the C++ comments were added to the C
standard or maybe a standard currently in the process of becoming official.
I find the old C comments very painful, but I also like tabs and not spaces,
though I can’t use this currently.

At Peter’s company he is one of the founders and will probably remain as
long as the company is in business. The rules of using ‘cpp’ for pure ‘c’
files makes sense for him at OSR, but where turnover at all levels is the
standard and not the exception it just won’t work. I don’t know for sure if
Microsoft will accept drivers written in ‘cpp’ (maybe C++ features too) for
in box inclusion. If they do, I have never seen it stated. I like C++
features in drivers, but I also know how often the compiler writers have
released compilers/linkers that produce bad code for drivers only. That is
probably the reason why the DDKs & WDKs have included a compiler, but if you
use a feature that have never been tested in drivers but places the
generated code in an incorrect segment, all the tests the Microsoft kernel
folks do won’t find it until you BSOD just because your latest task was to
reduce your driver’s footprint by using paged code.

In the last couple/three of years there was a compiler (C2.dll) that
generated incorrect code on the IA64. It took a special release of some
scripts, batch files, and new C2 modules to fix it. That is not an example
of what I mentioned above, but it does prove that some errors slip past any
and all tests.

wrote in message news:xxxxx@ntdev…
> Don,
>
>> It is amazing the number of times that people provide a .cpp file and say
>> don’t worry it is pure “C”, except for > the fact that it won’t compile
>> with the C compiler at all if you rename it .c!
>
> The solution is really simple. Name file with .c extension and compile it.
> If everything is OK, rename it to .cpp and compile it again, so that if
> there is some type mismatch, compiler will catch it (it is better to
> specify “treat warning as errors” option). What Peter speaks about is just
> the additional type safety net that comes at no price at all - is it so
> terribly difficult to change file extension and compile it twice, rather
> than once??? I really have no idea what you are arguing about…
>
> Anton Bassov
>

I can’t BELIEVE that I’m being put in the position of defending C++ in drivers, when I think C++ is such a positively horrible language. Ironic, no? Well, I probably get what I deserve. Karma.

Microsoft will logo drivers written in ESPERANTO if they can pass all the tests. I know that they logo drivers written in C++, as well as drivers written in C with C++ file types. There are definitely numerous drivers written in C++ that appear in the standard Windows distribution kit. Most written by Microsoft. Some well known and some less-so.

Right. I hear that, and I agree. Heck, You’ll see that particular “slip” in our (OSR’s) code, too. But like I said… is that really such a big sin? It’s against the natural order of things, I’ll agree. Not strict C. Not my personal PREFERENCE. But hardly anything I’d call evil.

So, my point here is that you don’t NEED to worry about small transgressions like this in ANY environment: Corporate, OSR, school, or whatever.

And if ANY company can’t keep control of whether the actual evil parts of C++ creep into their code (define the list however you want), then they’re not doing a very good job of engineering management, and I’d suggest they have a WHOLE lot more to worry about than a few inline declarations. Nobody does code reviews? Nobody tells their teammates that some hideous pile of polymorphic poo needs removed?

If the point is to enforce coding standards, then it sounds to me like you guys should be arguing that we should all use one of the many scanning tools to check that people are commenting their code sufficiently, that their cyclomatic complexity is appropriately low, and other such “quantitative” measures are met. Cuz if we don’t DO this, then code without comments, or code with nested switch statements (which drives up cyclomatic complexity) can “creep” in, and our projects will go down the pan.

It comes down to engineering discipline, plain and simple. Don’t write shit code, and don’t let your team members write shit code. In any language.

Peter
OSR

> I think the C++ comments were added to the C

standard or maybe a standard currently in the process of becoming
official.
I find the old C comments very painful, but I also like tabs and not
spaces, though I can’t use this currently.
… and C99 has them all … including the capability of declaring variables directly before use.

http:

// Oliver



DDKWizard and DDKBUILD: http:</http:></http:>

Hi,

This question certainly prompted a bit of discussion!

Anyway I appreciate the in and outs of this now and it appears to me that it
is probably safer just to use all C files.

Thanks for the help.

Regards FarmerJo

Hi,

Many thanks for your help and useful reply.

Regards FarmerJo

Now that you’ve seen the result, in future please do not post
anything that lights the blue touch paper around this topic.

Now where are those copies of Vista to hand out to the combatants ?

Mark.

At 11:15 28/04/2008, FarmerJo wrote:

Hi,

This question certainly prompted a bit of discussion!

Anyway I appreciate the in and outs of this now and it appears to me that it
is probably safer just to use all C files.

Thanks for the help.

Regards FarmerJo

> In the last couple/three of years there was a compiler (C2.dll) that
> generated incorrect code on the IA64. It took a special release of some
> scripts, batch files, and new C2 modules to fix it. That is not an example
> of what I mentioned above, but it does prove that some errors slip past any
> and all tests.

Maybe they couldn’t find an IA64 test machine. Just kidding; point taken.

Good morning all,

mm

David Craig wrote:

In most corporate settings where you have developers hired, fired, laid off,
transferred, and quit, it is very difficult to maintain control over coding
habits. There are standards that vary from company to company and
department to department and also developer to developer. If you name a
file with the ‘cpp’ extension, it is very easy for someone to add something
such as local variables just before their use and slip away from the rule of
no C++ features in the code. If you keep the extension as ‘c’ then you
can’t do that without starting a new block. I think I like the idea of
using the parameter in the sources file to treat all ‘c’ files as ‘cpp’, but
that of course means you need to do the compile twice to catch code that
violates the rules of C. I think the C++ comments were added to the C
standard or maybe a standard currently in the process of becoming official.
I find the old C comments very painful, but I also like tabs and not spaces,
though I can’t use this currently.

At Peter’s company he is one of the founders and will probably remain as
long as the company is in business. The rules of using ‘cpp’ for pure ‘c’
files makes sense for him at OSR, but where turnover at all levels is the
standard and not the exception it just won’t work. I don’t know for sure if
Microsoft will accept drivers written in ‘cpp’ (maybe C++ features too) for
in box inclusion. If they do, I have never seen it stated. I like C++
features in drivers, but I also know how often the compiler writers have
released compilers/linkers that produce bad code for drivers only. That is
probably the reason why the DDKs & WDKs have included a compiler, but if you
use a feature that have never been tested in drivers but places the
generated code in an incorrect segment, all the tests the Microsoft kernel
folks do won’t find it until you BSOD just because your latest task was to
reduce your driver’s footprint by using paged code.

In the last couple/three of years there was a compiler (C2.dll) that
generated incorrect code on the IA64. It took a special release of some
scripts, batch files, and new C2 modules to fix it. That is not an example
of what I mentioned above, but it does prove that some errors slip past any
and all tests.

wrote in message news:xxxxx@ntdev…
>> Don,
>>
>>> It is amazing the number of times that people provide a .cpp file and say
>>> don’t worry it is pure “C”, except for > the fact that it won’t compile
>>> with the C compiler at all if you rename it .c!
>> The solution is really simple. Name file with .c extension and compile it.
>> If everything is OK, rename it to .cpp and compile it again, so that if
>> there is some type mismatch, compiler will catch it (it is better to
>> specify “treat warning as errors” option). What Peter speaks about is just
>> the additional type safety net that comes at no price at all - is it so
>> terribly difficult to change file extension and compile it twice, rather
>> than once??? I really have no idea what you are arguing about…
>>
>> Anton Bassov
>>
>
>
>

Mark S. Edwards wrote:

With UAC turned off, and all new hardware Vista has proven to be fine. I
wouldn’t recommend an upgrade
for older systems (that just wouldn’t work), but if you can buy all new
everything it is quite nice.

Damn near all bitchin’ I’ve heard regarding Vista had to do with driver
support for existing peripherals, UAC, or
the “Vista Capable” vs “Vista Ready” logos.

Solutions to these problems:

  1. Don’t be a cheap-ass and expect a new OS to use old deprecated hardware.
  2. Turn off UAC
  3. Research before you buy a new system!

Reasons to think about a full system + OS upgrade:

  1. Address Space Load Randomization
  2. The whole usermode portion is built using stack cookies
  3. Unlike a few years ago, most all new CPU’s incorporate hardware based
    DEP (reason to buy a new system)
  4. WFP (a.k.a. SFP) is fully implemented.

Regarding driver development, Microsoft did address the communities
concerns with test signatures and the
boot option. While not perfect, whatever is?

I’m kinda getting tired of hearing people masturbate to these negative
“Penthouse forum” type columns on various
“computer news” websites without ever even trying Vista on a non-sucky
system.

SP1 has also been working fine for the last month and a half. Prior to
it, this new system worked fine also.

Please do send me some of these Vista licenses your wanting to give out.

Matt

Now that you’ve seen the result, in future please do not post anything
that lights the blue touch paper around this topic.

Now where are those copies of Vista to hand out to the combatants ?

Mark.

At 11:15 28/04/2008, FarmerJo wrote:
> Hi,
>
> This question certainly prompted a bit of discussion!
>
> Anyway I appreciate the in and outs of this now and it appears to me
> that it
> is probably safer just to use all C files.
>
> Thanks for the help.
>
> Regards FarmerJo
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Lost of people seem to be getting out the wrong side of bed on this
thread. Perhaps you didn’t see the original part of this in context.

As for my personal use of Vista, I ran several beta versions and then
the RTM version for a year before upgrading to SP1 and had much the
same view what you wrote below. However, after experimenting with
Server 2008 as a workstation, there’s no way I’m going back to Vista
except as when I have to test on it. Given that Server 2008 and
Vista SP1 have the same kernel there’s a vast difference in
performance and stability that really makes you wonder just what the
workstation guys did to hobble Vista so much.

Mark.

At 12:36 28/04/2008, Matt wrote:

Mark S. Edwards wrote:

With UAC turned off, and all new hardware Vista has proven to be
fine. I wouldn’t recommend an upgrade
for older systems (that just wouldn’t work), but if you can buy all
new everything it is quite nice.

Damn near all bitchin’ I’ve heard regarding Vista had to do with
driver support for existing peripherals, UAC, or
the “Vista Capable” vs “Vista Ready” logos.

Solutions to these problems:

  1. Don’t be a cheap-ass and expect a new OS to use old deprecated hardware.
  2. Turn off UAC
  3. Research before you buy a new system!

Reasons to think about a full system + OS upgrade:

  1. Address Space Load Randomization
  2. The whole usermode portion is built using stack cookies
  3. Unlike a few years ago, most all new CPU’s incorporate hardware
    based DEP (reason to buy a new system)
  4. WFP (a.k.a. SFP) is fully implemented.

Regarding driver development, Microsoft did address the communities
concerns with test signatures and the
boot option. While not perfect, whatever is?

I’m kinda getting tired of hearing people masturbate to these
negative “Penthouse forum” type columns on various
“computer news” websites without ever even trying Vista on a non-sucky system.

SP1 has also been working fine for the last month and a half. Prior
to it, this new system worked fine also.

Please do send me some of these Vista licenses your wanting to give out.

Matt

>Now that you’ve seen the result, in future please do not post
>anything that lights the blue touch paper around this topic.
>
>Now where are those copies of Vista to hand out to the combatants ?
>
>Mark.
>
>
>At 11:15 28/04/2008, FarmerJo wrote:
>>Hi,
>>
>>This question certainly prompted a bit of discussion!
>>
>>Anyway I appreciate the in and outs of this now and it appears to me that it
>>is probably safer just to use all C files.
>>
>>Thanks for the help.
>>
>>Regards FarmerJo
>
>
>—
>NTDEV is sponsored by OSR
>
>For our schedule of WDF, WDM, debugging and other seminars visit:
>http://www.osr.com/seminars
>
>To unsubscribe, visit the List Server section of OSR Online at
>http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Mark S. Edwards wrote:

Mark, I didn’t mean to vent on you, that wasn’t my intention at all. I
was just grippin’ in general, however, that last line in that
post about you giving away licenses in retrospect does make it appear I
was targeting you personally. I didn’t mean it that way.

My bad, my apologizes.

Matt

Lost of people seem to be getting out the wrong side of bed on this
thread. Perhaps you didn’t see the original part of this in context.

As for my personal use of Vista, I ran several beta versions and then
the RTM version for a year before upgrading to SP1 and had much the
same view what you wrote below. However, after experimenting with
Server 2008 as a workstation, there’s no way I’m going back to Vista
except as when I have to test on it. Given that Server 2008 and Vista
SP1 have the same kernel there’s a vast difference in performance and
stability that really makes you wonder just what the workstation guys
did to hobble Vista so much.

Mark.

At 12:36 28/04/2008, Matt wrote:
> Mark S. Edwards wrote:
>
> With UAC turned off, and all new hardware Vista has proven to be
> fine. I wouldn’t recommend an upgrade
> for older systems (that just wouldn’t work), but if you can buy all
> new everything it is quite nice.
>
> Damn near all bitchin’ I’ve heard regarding Vista had to do with
> driver support for existing peripherals, UAC, or
> the “Vista Capable” vs “Vista Ready” logos.
>
> Solutions to these problems:
> 1. Don’t be a cheap-ass and expect a new OS to use old deprecated
> hardware.
> 2. Turn off UAC
> 3. Research before you buy a new system!
>
> Reasons to think about a full system + OS upgrade:
>
> 1. Address Space Load Randomization
> 2. The whole usermode portion is built using stack cookies
> 3. Unlike a few years ago, most all new CPU’s incorporate hardware
> based DEP (reason to buy a new system)
> 4. WFP (a.k.a. SFP) is fully implemented.
>
> Regarding driver development, Microsoft did address the communities
> concerns with test signatures and the
> boot option. While not perfect, whatever is?
>
> I’m kinda getting tired of hearing people masturbate to these
> negative “Penthouse forum” type columns on various
> “computer news” websites without ever even trying Vista on a
> non-sucky system.
>
> SP1 has also been working fine for the last month and a half. Prior
> to it, this new system worked fine also.
>
> Please do send me some of these Vista licenses your wanting to give out.
>
> Matt
>
>
>
>
>> Now that you’ve seen the result, in future please do not post
>> anything that lights the blue touch paper around this topic.
>>
>> Now where are those copies of Vista to hand out to the combatants ?
>>
>> Mark.
>>
>>
>> At 11:15 28/04/2008, FarmerJo wrote:
>>> Hi,
>>>
>>> This question certainly prompted a bit of discussion!
>>>
>>> Anyway I appreciate the in and outs of this now and it appears to
>>> me that it
>>> is probably safer just to use all C files.
>>>
>>> Thanks for the help.
>>>
>>> Regards FarmerJo
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> Unlike a few years ago, most all new CPU’s incorporate hardware based DEP

(reason to buy a new system)

…but no reason to run 32-bit OS on it - don’t forget that all new CPU’s incorporate support for 64-bit extensions as well…

Anton Bassov

For YOU. YOU like it, YOU use it. I’m gonna continue to run 64-bit Server 2003 on my dev box, thank you (I got it free at the last DDC!).

I’m waiting for Windows 7 SP1,

Peter
OSR