c++

Actually, I can state that even though you feel inline declarations are good
things, this was argued in the C++ standards committee whether it should be
removed from the language! On one side were the folks saying it makes the
code more reliable, and on the other side were the folks who argued that is
makes accidents such as declaring X at the beginning of a function, then
having an inline declaration of X, with the poor maintenance programmer
missing the second declaration. Like a lot of things with C++ the
arguments were long and heated, and in the end added nothing to the state of
the art, since it was pointed out that long before C++ the same arguments
happened for a number of other languages.

–
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

ā€œOliver Schneiderā€ wrote in message
news:xxxxx@ntdev…
> Anton, Maxim,
>
> (Anton wrote:)
>> So there is only one question left - do we really need all the above (and
>> quite a few features beyond that) in the kernel mode???
> wrong question, IMO. The question more is whether you or me or anyone
> else him/herself or in team needs these features or finds them useful. It
> seems that the opponents of C++ in KM are quicker to tell everyone how
> to do what (i.e. not use C++), than the proponents are :wink:
>
> (Maxim wrote:)
>> For RAII code to be readable, your should declare only after {, so that
>> {} will be the locked code path. Otherwise, the code reader will be
>> confused a lot on what is the locked code path.
> Sure.
>
>> Correct. Now note lots of unexperienced C++ coders, who know the language
>> features (including the most recent ones of 2000ies), but have no
>> intuitive sense of how to do things easily.
> Then educate them, if it’s in your company.
>
>> In reality, the bug with passing a NULL pointer somewhere is the most
>> uncommon bug ever met :slight_smile:
> So? Uncommon doesn’t mean it can’t happen. And making the programmer go
> through hoops to make it happen, will at least get the programmer thinking
> (hopefully!), since it should then dawn them that this was not intended.
>
> No question, references are more restrictive than pointers, but that’s
> the feature, otherwise it would be merely the clone of the functionality
> of pointers. References allow you to express requirements in code and the
> compiler will complain if the caller doesn’t comply. I thought there was a
> broad consensus among programmers that forcing compiler errors, where the
> alternative would be runtime errors (which need handling and ā€œ~5 times
> more code to implementā€ :wink: …) was a good thing. Seems I was wrong.
>
> People use SAL to help PREfast understand the code. Use a few (or more)
> well-chosen C++ features and you’ll help the compiler to understand your
> code (and intentions).
>
>> This leads to ~5 times more code to implement the same, and to wrong
>> choice of language features to implement the task (like trying to do
>> polymorphic object loading from a stream using references instead of
>> pointers - switching to pointers is 10 times easier then doing this with
>> references which have issues with autocast in the inheritance tree).
> I had something else in mind, e.g. the typical:
>
> if(void* x = malloc(12345))
> {
> if(void* y = malloc(23456))
> {
> // do some things …
> if(SomeWeirdError())
> {
> HandleError();
> free(y);
> free(x);
> return -1;
> }
> // do some other things here
> free(y);
> }
> free(x);
> }
>
> You can make the code more modular and readable by using RAII here with
> the feature that classes on stack are destroyed when going out of scope
> alone. And if the original code with malloc/free (which is the kind of C
> I usally encounter in .cpp files of the aforementioned kind of people) ā€œis
> probably the best way of C++ useā€, well then I am out of the discussion.
> It doesn’t make sense to argue further then, because we have fundamentally
> different opinions on how to use/write C++. As was stated before by
> others, if you don’t abuse C++, it won’t abuse you!
>
>
> // Oliver
> –
> ---------------------------------------------------
> May the source be with you, stranger :wink:
>
> ICQ: #281645
> URL: http://assarbad.info | http://windirstat.info |
> http://blog.assarbad.info
>
>

ā€œOliver Schneiderā€ wrote in message
news:xxxxx@ntdev…
>> I don’t, but since it appeared/appears that the majority of the frequent
>> posters on NTDEV were/are opposed to C++ classes in KM, I thought I
>> should show that there is a lot more besides the obvious.

Actually classes are probably one of the few things that can be argued for,
but even here there is a significant challenge. If you pin down the C++
and OO gurus they admit that when you have to fit an OO model into a system
that has a lot of features but is not OO you either have to build a lot of
infastructure code hiding the original system, of your model breaks down
quickly.

Mark Roddy and I both were involved with a multi-firm UNIX effort for a
next-generation system, that included a number of folks who had worked at
Bell Labs. Originally it was going to use C++ extensively, but in the end
they had decided on almost a flat class structure, where there were simple
classes for things like 64-bit integers, but otherwise mostly C style code.

–
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

I was in Doron’s office yesterday, and he suggested that we stick to discussing more important topics… such as whether you prefer to indent code with tabs versus spaces. I see the wisdom of his recommendation. Am I the only one?

I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs is either stupid, an MVP, or hasn’t searched the archives before posting. I’d like to know what product they’re working on so I can avoid ever installing it on my system.

And for those of you who think spaces are less efficient (multiple characters to process instead of just one tab character), you may have a point. But there was a paper a number of years back that said this wasn’t true (unfortunately, it was written in Tagalog and I lost the citation – there are so few really GOOD Tagalog web sites, anyhow).

Kainin mo iyan,

Peter
OSR

Peter,

I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs is either stupid,
an MVP, or hasn’t searched the archives before posting. I’d like to know what
product they’re working on so I can avoid ever installing it on my system.

I appreciate you irony. The funniest thing here is that someone may take it seriously. More on it below…

And for those of you who think spaces are less efficient (multiple characters
to process instead of just one tab character), you may have a point.

Believe it or not, there is ā€œnot-so-uncommonā€ belief among the newbies (mainly the ones who have migrated to to from VB and friends) that the more code you cram into a single line, the faster your program is going to run…

Anton Bassov

It depends on what you mean. I prefer to indent my code by pressing the TAB
key, which causes my editor to insert space characters. It gets really fun
when one developer’s editor is set to tabs and another’s is set to spaces.

On a related topic, why is the K&R brace placement style so damn popular?
The only reason they used it was to save space in the book. Now it seems to
be almost a universal standard, when anyone with half a brain can see that
Allman style makes for code that can actually be read.

  • Dan.

P.S. I suppose this response could also be considered a vote for top
posting.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, January 26, 2008 8:11 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] c++

I was in Doron’s office yesterday, and he suggested that we stick to
discussing more important topics… such as whether you prefer to indent
code with tabs versus spaces. I see the wisdom of his recommendation. Am I
the only one?

I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs is
either stupid, an MVP, or hasn’t searched the archives before posting. I’d
like to know what product they’re working on so I can avoid ever installing
it on my system.

And for those of you who think spaces are less efficient (multiple
characters to process instead of just one tab character), you may have a
point. But there was a paper a number of years back that said this wasn’t
true (unfortunately, it was written in Tagalog and I lost the citation –
there are so few really GOOD Tagalog web sites, anyhow).

Kainin mo iyan,

Peter
OSR


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

I think the main reason for not using tabs is that it is not conistent. In a
team env., when others looks at my code, they will see that I did not format
it correctly. Spaces has the consistency.

Also if think, the debugger ( Windbg ) gets totally lost, and shows the src
is a very unformatted way when tabs are used.

One other thing I like about VS IDE is to turn on the column boundary, so
that statement does not go beyond some specified number of chars/line ( say
80 or 100 )

-pro
----- Original Message -----
From: ā€œDan Kylerā€
To: ā€œWindows System Software Devs Interest Listā€
Sent: Saturday, January 26, 2008 8:49 AM
Subject: RE: [ntdev] c++

> It depends on what you mean. I prefer to indent my code by pressing the
> TAB
> key, which causes my editor to insert space characters. It gets really
> fun
> when one developer’s editor is set to tabs and another’s is set to spaces.
>
> On a related topic, why is the K&R brace placement style so damn popular?
> The only reason they used it was to save space in the book. Now it seems
> to
> be almost a universal standard, when anyone with half a brain can see that
> Allman style makes for code that can actually be read.
>
> - Dan.
>
> P.S. I suppose this response could also be considered a vote for top
> posting.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
> Sent: Saturday, January 26, 2008 8:11 AM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] c++
>
> I was in Doron’s office yesterday, and he suggested that we stick to
> discussing more important topics… such as whether you prefer to indent
> code with tabs versus spaces. I see the wisdom of his recommendation. Am
> I
> the only one?
>
> I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs is
> either stupid, an MVP, or hasn’t searched the archives before posting.
> I’d
> like to know what product they’re working on so I can avoid ever
> installing
> it on my system.
>
> And for those of you who think spaces are less efficient (multiple
> characters to process instead of just one tab character), you may have a
> point. But there was a paper a number of years back that said this wasn’t
> true (unfortunately, it was written in Tagalog and I lost the citation –
> there are so few really GOOD Tagalog web sites, anyhow).
>
> Kainin mo iyan,
>
> Peter
> OSR
>
>
> —
> 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

Peter,

You must be joking, of course. You should know very well that there are much more important issues to be discussed. For example:

1.) Variable and procedure naming conventions.
2.) Use of PostScript language interpreters in the kernel. (I don’t think anyone has brought this up before…).

Think of PostScript as a general-purpose OO language. After MS research added the PS interpreter to the kernel at load time the driver would simply load the PS text and interpret it in real time. Tiny ā€œdriverā€.

Whadya think? :slight_smile:

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-312846-
xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, January 26, 2008 10:11 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] c++

I was in Doron’s office yesterday, and he suggested that we stick to
discussing more important topics… such as whether you prefer to
indent code with tabs versus spaces. I see the wisdom of his
recommendation. Am I the only one?

I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs
is either stupid, an MVP, or hasn’t searched the archives before
posting. I’d like to know what product they’re working on so I can
avoid ever installing it on my system.

And for those of you who think spaces are less efficient (multiple
characters to process instead of just one tab character), you may have
a point. But there was a paper a number of years back that said this
wasn’t true (unfortunately, it was written in Tagalog and I lost the
citation – there are so few really GOOD Tagalog web sites, anyhow).

Kainin mo iyan,

Peter
OSR


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

Now wait a minute, Thomas. We haven’t even discussed tab size yet…

At 11:44 AM 1/26/2008, you wrote:

Peter,

You must be joking, of course. You should know very well that there
are much more important issues to be discussed. For example:

1.) Variable and procedure naming conventions.
2.) Use of PostScript language interpreters in the kernel. (I don’t
think anyone has brought this up before…).

Think of PostScript as a general-purpose OO language. After MS
research added the PS interpreter to the kernel at load time the
driver would simply load the PS text and interpret it in real time.
Tiny ā€œdriverā€.

Whadya think? :slight_smile:

Thomas F. Divine

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-312846-
> xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
> Sent: Saturday, January 26, 2008 10:11 AM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] c++
>
> I was in Doron’s office yesterday, and he suggested that we stick to
> discussing more important topics… such as whether you prefer to
> indent code with tabs versus spaces. I see the wisdom of his
> recommendation. Am I the only one?
>
> I’ll start: I think tabs are ā€œof the devilā€ and anybody who uses tabs
> is either stupid, an MVP, or hasn’t searched the archives before
> posting. I’d like to know what product they’re working on so I can
> avoid ever installing it on my system.
>
> And for those of you who think spaces are less efficient (multiple
> characters to process instead of just one tab character), you may have
> a point. But there was a paper a number of years back that said this
> wasn’t true (unfortunately, it was written in Tagalog and I lost the
> citation – there are so few really GOOD Tagalog web sites, anyhow).
>
> Kainin mo iyan,
>
> Peter
> OSR
>
>
> —
> 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

> No question, references are more restrictive than pointers, but *that’s* the
feature,

otherwise it would be merely the clone of the functionality of pointers.

Being not NULLable is a minor unimportant quirk, which surely cannot pay for
lack of D& autocast to B&.

What is important with references is lack of * and & operators, which makes
returning lvalue or passing lvalue as parameter (the primary purpose of
references) syntactically nice.

complain if the caller doesn’t comply. I thought there was a broad consensus
among programmers that forcing compiler errors, where the alternative would be
runtime errors (which need handling and ā€œ~5 times more code to implementā€ :wink:
…)
was a good thing.

Depends. D* autocasts to B*, and D& does not autocast to B&. This is a by far
more important then NULLability checks.

the original code with malloc/free (which is the kind of C I usally encounter
in .cpp
files of the aforementioned kind of people) ā€œis probably the best way of C++
useā€,

Using exceptions and destructors to clean up after allocation failure _requires
to wrap any allocated object into a C++ class with a destructor. For instance,
HANDLE must be wrapped, all memory pointers must be wrapped, and so on.

Otherwise you will have leaks on each exception.

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

> would agree with, if that is in fact what he is saying. I don’t use

references much myself, except in the case of overloaded operators,

This is for what references were invented.

which I don’t use much either and are for all practical purposes
unusable with out them, because they do not declare the intent or lack
there of to modify an argument,

Correct.

UpdateStructure(&S);

is better then

UpdateStructure(S);

considered from either a risk or reward point of view. For example,
using cout over printf().

cout is one of the worst C++ features, so, I always use printf even in C++
code.

Using left shift operator for printing seems brain damage for me.

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

> exception of ā€˜Extreme Programming;’

Well, this is PM’s menace, not the developers menace :slight_smile:

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

Thomas,

2.) Use of PostScript language interpreters in the kernel. (I don’t think anyone
has brought this up before…).

I think this is going to be the next step. For the time being no one (yet) spoke about writing drivers in interpreted languages, but the managed ones are already there. Just search the web for Singularity project that is done by MSFT research - they are writing the whole OS in C#. Just pay a special attention to the performance tables - according to them, its performance is comparable to that of NT (on some operations is even better), with both Linux and FreeBSD, in all respects, dragging miles behind all MSFT OSes…

However, as Michael properly pointed out, before we can proceed to it we have to decide upon the tab size first - I think this factor must be of crucial importance to the OS that is written in any
interpreted language, be it JavaScript or VBScript…

Anton Bassov

>tabs versus spaces.

Spaces. With this, the code looks the same regardless of the editor’s settings
on a particular desktop.

GNU code uses tabs and assumes the tab width of 8. So, opening a GNU source
file in MSVC, where the default is tab width 4, leads to funny results.

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

> On a related topic, why is the K&R brace placement style so damn popular?

…and I cannot understand the space between ā€œifā€ and ā€œ(ā€, and never ever typed
this space.

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

>2.) Use of PostScript language interpreters in the kernel.

No, no, Haskell is smarter :slight_smile:

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

Oh fine, but if you are going to post Microsoft’s quasi official position on
this, it should be qualified by the fact that concurrent to the release of
this white paper, Microsoft was developing a C++ based object oriented
driver framework, subsequently released as KMDF. Goose, gander.

On Jan 25, 2008 4:52 AM, amitr0 wrote:

> lots have been already said and done with this thread. But on one gave the
> ā€˜real’ answers. while it is true that the poster whud read older postings
> before submitting, we shud appreciate tht electronic searches still depend
> on search strings and might not always reveal thebest results. any how, i
> simply googled, and here is a copy paste from what i found…hope this
> helps…
>
> C++ Issues for Kernel-Mode Drivers
>
> Microsoft developers have discovered a number of areas where C++ presents
> particular problems for kernel-mode drivers.
>
> Code in Memory
> The most severe problem with using C++ for writing kernel-mode drivers is
> the management of memory pages, particularly code in memory, rather than
> data. It is important that large drivers be pageable, and paged code is not
> always in memory. All of the code that will be needed must be resident
> before the system enters a state in which paging cannot occur.
>
> The way the C++ compiler generates code for non-POD classes and templates
> makes it particularly difficult to know where all the code required to
> execute a function might go and thus difficult to make the code safely
> pageable. The compiler automatically generates code for at least the
> following objects. These objects are put ā€œout of line,ā€ and the developer
> has no direct control over the section in which they are inserted, which
> means they could happen to be paged out when needed.
>
> ?
>
> Compiler-generated code such as constructors, destructors, casts, and
> assignment operators. (These can often be explicitly provided, but it
> requires taking care to recognize that they need to be provided.)
>
> ?
>
> Adjustor thunks, used to convert between various classes in a hierarchy.
>
> ?
>
> Virtual function thunks, used to implement calls to virtual function.
>
> ?
>
> Virtual function table thunks, used to manage base classes and
> polymorphism.
>
> ?
>
> Template code bodies, which are emitted at first use unless explicitly
> instantiated.
>
> ?
>
> The virtual function tables themselves.
>
> The C++ compiler does not provide mechanisms for direct control of where
> these entities are placed in memory. The pragmas necessary to control memory
> placement were not designed with C++ in mind. #pragma alloc_text cannot be
> used to control the location of a member function because (for several
> reasons) there is no way to name the member function. The scope of #pragma
> code_seg is ambiguous for compiler-generated functions, expanded template
> bodies, and compiler-generated thunks. There is no mechanism at all for
> controlling the location of virtual function tables, since they are not
> quite either code or data from the point of view of the compiler (they go
> into a section all their own).
>
> If a function in a header is declared inline, but the compiler does not
> generate inline code for it, the function may be emitted in more than one
> code segment depending on where the function is used. When a class template
> is instantiated, it is generated in the section that is current at the point
> of first use, and it is not always immediately obvious which section that
> is. Both of these issues can lead to code being pageable when it should not
> be, or vice versa.
>
> If a class hierarchy is in use, whether code for a base class needs to be
> in memory when the derived class is accessed depends on exactly which
> functions in the base class are called from the derived class (and whether
> the compiler can inline them), as well as what sections they were emitted
> in. For example, if the derived class provides a method that uses no base
> class methods, the base class code need not be in memory. However, it is
> difficult to know when that is the case. Additionally, any thunks used with
> the hierarchy and its classes might also need to be resident in memory.
>
> Stack
> The compiler has always been free to generate additional data on the
> stack, such as creating temporary objects, deferring call cleanup, and other
> actions that use the stack in a hidden fashion. There are few differences
> between C and C++ with respect to the way a single function uses the stack,
> but because of the additional mechanisms that usually result in more
> function calls, C++ will often use more total stack. You should keep stack
> size in mind, as you would in any programming language when stack space is
> limited.
>
> Exceptions also have an effect on the stack. See ā€œExceptions and RTTIā€
> later in this paper.
>
> Dynamic Memory
> Driver development tools such as Driver Verifier rely on tagged memory to
> validate memory usage in drivers. Using operator new and operator
> delete
to allocate and free memory weakens the ability of these tools to
> detect memory leaks and other problems in driver code.
>
> In user space,* operator new* and operator delete are convenient, but
> they can become cumbersome in drivers that use multiple memory pools or
> tagged memory. Because ā€œplacement newā€ takes additional operands, it is
> possible to pass in the information needed to select memory pools or
> generate tags into an overloaded operator new , but this is not much
> easier than using the memory functions directly. Because there is no
> ā€œplacement deleteā€ with additional arguments to pass in a tag or a pooltype,
> there is no way to pass in a tag (or memory control, if needed) when using
> operatordelete, making it impossible to check that the tag at the point
> of release was the intended one, thus defeating much of the benefit of using
> tagged memory. It is possible to delete memory without providing a tag,
> but in each case you will need to decide whether the risks and disadvantages
> of not using tags in driver code overcome the apparent convenience.
>
> Memory tracing tools often record the return address of the function that
> made an allocation. Some C++ compilers implement operator new as a
> function, causing all allocations to appear to come from a single location
> and defeating the purpose of that aspect of the memory tracing tool. This
> can be addressed, but you will have to determine for yourself if there is a
> benefit in doing so over using memory allocation directly.
>
> Libraries
> There are a number of distinct concerns in creating and using libraries:
>
> ?
>
> The name of exported C++ functions can vary from one release to another.
>
> ?
>
> Not all of the functions available in user mode are available in the
> kernel-mode libraries.
>
> ?
>
> The Standard Template Library is designed to work with data objects from a
> single DLL.
>
> C++ functions are exported based on their entire signature, not on their
> name alone (as C functions are). The name of a C++ function is ā€œmangledā€ to
> contain type information, which becomes part of its signature. Although the
> rules for name mangling are fairly stable, there is no guarantee that the
> mangled names will be the same from release to release of the compiler.
> Therefore, C++ functions cannot be reliably exported to a library from one
> release to the next, although functions that can be represented as extern
> ā€œCā€
functions can. In addition, the use of a .def file can help mitigate
> the problem. Note that extern ā€œCā€ functions are unique only on the basis
> of name, not the entire signature as in C++.
>
> Not all library functions are available in kernel mode, particularly those
> associated with the ā€œadvancedā€ C++ language features. The Standard Template
> Library is the ā€œusualā€ way to implement many C++ concepts such as variably
> sized arrays. However, it is unsafe to simply assume that the Standard
> Template Library is present and usable. Although much of the Standard
> Template Library is implemented as source code in headers, it occasionally
> uses library functions or other features that are not available or usable in
> the kernel environment.
>
> The Standard Template Library is also based on the assumption that each
> data object it uses exists in only a single DLL. Although in most cases it
> works to pass references to POD objects across DLL boundaries, passing
> references to more complex structures such as lists may cause runtime
> failures that can be hard to diagnose. Known issues include the fact that
> freeing memory in a DLL other than the one in which the memory was allocated
> can cause failures (at least for debug-mode compiles) and that the ā€œend of
> listā€ marker differs between DLLs, which can cause unexpected runaway list
> searches. You must be aware of these problems and take steps to prevent
> them.
>
> We do not recommend using Standard Template Library functions in a
> kernel-mode driver, because it is not possible to assume that the Standard
> Template Library is there and ā€œjust works.ā€ In the case of kernel-mode code,
> understanding precisely how a particular data structure is implemented helps
> assure that it does not violate the requirements of kernel space. It is also
> possible that a specialized implementation will be smaller than the more
> general Standard Template Library functions, although the library is often
> very good in that regard.
>
> Exceptions and RTTI
> It is tempting to use C++ exceptions, but they are difficult to implement
> in kernel mode. C++ exceptions require a kernel-mode-safe library, which
> does not currently exist. They also present an unavoidable runtime problem,
> because exception records that are generated when an exception is thrown are
> large objects on the very limited stack. On x86 systems, exception records
> are not particularly large (although they are large compared with many
> typical stack frames), but on Intel Itanium systems they are quite large: 3K
> to 4K, or one-sixth to one-eighth of the available 24K stack space. To
> preserve portability of a driver to 64-bit platforms, exceptions would have
> to be used in a very limited way, even on the x86 architecture. The
> rethrow
operator can cause multiple exception records on the stack. Note
> that Structured Exception Handling (* try* /* except*/__finally) is
> available in kernel mode, although the space concerns remain. C++ exceptions
> have a number of semantic subtleties that prevent them from simply mapping
> onto Structured Exception Handling.
>
> Run-time type information (RTTI) also requires a library that does not
> currently exist for C++ in kernel mode. So far, there have been few, if any,
> requests for this in kernel-mode code. Whether this lack of demand is a
> consequence of the other problems masking it or because it is not useful in
> kernel mode is unknown.
>
> Compiler Versions
> Although the C++ language standard is stable, implementation techniques
> are still evolving. Consequently, compiler versions may change the way
> generated code operates. Such changes are unlikely to affect user-mode code,
> but they can affect kernel-mode code in which more of the underlying
> implementation is exposed to (and sometimes provided by) driver developers;
> version-to-version interoperability of kernel-mode code is not guaranteed.
>
> You should carefully control any interface between two drivers or a driver
> and the operating system, usually by writing the interface in C instead of
> C++. Otherwise, version-to-version incompatibilities in the C++
> implementation may cause interoperability failures.
>
> Static and Global Scope Variables and Initialization
> C++ static variables (declared at either global or local scope) present a
> number of problems for drivers.
>
> The C++ standard allows static variables declared at local scope to be
> initialized at the time of first use (the first time the scope is entered).
> The way this is implemented both creates the possibility of race conditions
> during initialization and a particularly high risk of unintended data
> sharing between threads, because variables declared static are globally
> static, not per-thread. For globally static data (shared among threads) it
> is best to do it explicitly at global scope, to make sure access protections
> appropriate to the situation are applied.
>
> If a C++ global object requires initialization (a global constructor) is
> declared, there is no mechanism for the constructor to be called. Global
> objects that require constructors should either not be used, or you must
> develop a mechanism to assure that the constructor is called. Several
> sources on the Web claim to have solved this problem, and one of those
> solutions might work for you.
>
> The order of initialization of global objects is not specified by the C++
> standard, so even if there were a mechanism to call their constructors,
> either the order of initialization must be explicitly controlled by the
> driver code, or it must not matter.
>
>
> On Jan 25, 2008 3:12 PM, wrote:
>
> > Reinhard,
> >
> > > the problem is that many people on this list don’t want to see the
> > same
> > > arguments again and again
> >
> > Sure. This is why, in my opinion, it makes sense to isolate these
> > arguments on some separate thread(s) that will be completely ignored by the
> > vast majority of readers…
> >
> > > Of couse nobody must read the read. But what is it worth then?
> >
> > Well, even if thread is of no interest to overwhelming majority of list
> > readers (let’s say 95%),
> > it is still of interest to the remaining 5% (because otherwise no one
> > would post to it, in the first place, so that it would just die in itself).
> > This NG has more than 50K subscribers, which, if we assume 95% vs 5% ratio,
> > still gives us 2 500 potential readers. You don’t really want to deny them
> > a chance to discuss a topic that is of interest to them, do you (please
> > note that I am not among them - I’ve got no interest in C vs C++ topic
> > whatsoever). If you do … then think again - if they have no chance to
> > do it here, they will be just raising this issue on other threads,
> > effectively hijacking them. Just to give you an idea, in the last 2 weeks I
> > saw C vs C++ discussion on 3 threads that I have participated in…
> >
> > Anton Bassov
> >
> > —
> > 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
> >
>
>
>
> –
>
> - amitr0 — 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 Roddy

Let’s just make it ā€˜better’ and define the tab setting as zero. That would
make it so much more ā€˜interesting’, although having an editor that randomly
chooses a tab width with each invocation does seem even more ā€˜interesting’.
How about the random being applied randomly per file per invocation or
switch to that file? Maybe have the editor do a ā€˜beautify’ of the ā€˜C’ code
switching between the three main brace placements each time the file is
opened?

wrote in message news:xxxxx@ntdev…
> Thomas,
>
>> 2.) Use of PostScript language interpreters in the kernel. (I don’t think
>> anyone
>> has brought this up before…).
>
> I think this is going to be the next step. For the time being no one
> (yet) spoke about writing drivers in interpreted languages, but the
> managed ones are already there. Just search the web for Singularity
> project that is done by MSFT research - they are writing the whole OS in
> C#. Just pay a special attention to the performance tables - according to
> them, its performance is comparable to that of NT (on some operations is
> even better), with both Linux and FreeBSD, in all respects, dragging miles
> behind all MSFT OSes…
>
>
> However, as Michael properly pointed out, before we can proceed to it we
> have to decide upon the tab size first - I think this factor must be of
> crucial importance to the OS that is written in any
> interpreted language, be it JavaScript or VBScript…
>
> Anton Bassov
>
>

Oh, no!! Not a Functional Programming Language. I almost brought this up during the previous discussion of APL (another Functional Programming Language), but I was busy being stern.

I am sooooooo sick of hearing about Haskell and Erlang and F# from folks in the Digital Signal Processing area. ā€œWell, Erlang is a great language, especially when coupled with OTP and it runs across many different platformsā€ – YEAH… if you disable multiprocessor support it’ll even run on Windows.

Arrrrgh!! I’m entirely convinced that people really just wanna do something DIFFERENT. It doesn’t need to be better.

Well, except C#… which is clearly an improvement over C++, given that C++ is very obviously shit. That’s my story, and…

Peter
OSR

(OTOH, I like the idea of writing drivers in Postscript even better than the idea of writing drivers in C#. This’ll let us write the documentation, and just interpret the driver at runtime. Clearly the wave of the future.)

> I would completely agree with your assessment of ā€œusing the smart…,ā€

and add that the situation is a party compared to what people who
learned C# first do, like have fifteen different singlets in one
program, and look at you like you are some out of your mind dinosaur if
you don’t do the same.

I recently had the misfortune of working on a C# program that was
written like that. It was unpleasant. My eyes are still hurting.

While we are at it, Peter, here is my thoughts :slight_smile:

I don’t completely throw away the idea of functional programming.

Sure, for kernel mode we are so used to advanced(structured) assembly ( ie.,
C) that I will have hard time conceptualizing the use of functional language
in this environment, but again I don’t know enough to throw the idea
completely.

In the research environment, sure they would like to do something new,
different, … But we all know, if something is really slick, it would fly
sooner or later.

Functional programming’s main promise ( as I understood a quarter of a
century ago ) is to have a provably correct program synthesis. In plain
words, I write programs that would/could be verified for its correctness.
This is certainly a good thing. Lot of these languages have either lack of
expressiveness or difficult to express anything complex. And in earlier try,
lot of them were interpretive.

IIRC, there is a similarity between turing model and corresponding categorie
theory for functional languages. And category theory is a branch of field
theory, and it in turn is a branch of abstract algebra. In the last 20 years
there are a lot of advance in these areas specially triggered towards
functional programming. There the main emphasis is to have an automatic
proof method… This is a big thing for lot of programming areas. And the
attack to this is not from kernel programming or user programming point of
view, rather the proof of correctness is the angle of attack. And there are
people who also does try to design machine architecture based on problem
domain or language domain. An example is Belle ( the chase machine has quite
a few HW level optimization for search techniques – that I read a while
ago ).

On the pragmatic side –

  1. I would surely like to see automatic ( static) complexity analysis of a
    piece of code
  2. Automatic proof of correctness of a piece of code.

Perhaps, there is a lot of advances already in those area, I would not ever
be able to be part of it. But I would love to see that comes forward and be
used by commercial software…

This has its place :slight_smile:

Finally, if anyone is thinking to buy a good book on programming ā€œBeautiful
Codeā€ is one to look at!

-pro
----- Original Message -----
From:
To: ā€œWindows System Software Devs Interest Listā€
Sent: Saturday, January 26, 2008 7:20 PM
Subject: RE:[ntdev] c++

>


>
> Oh, no!! Not a Functional Programming Language. I almost brought this up
> during the previous discussion of APL (another Functional Programming
> Language), but I was busy being stern.
>
> I am sooooooo sick of hearing about Haskell and Erlang and F# from folks
> in the Digital Signal Processing area. ā€œWell, Erlang is a great language,
> especially when coupled with OTP and it runs across many different
> platformsā€ – YEAH… if you disable multiprocessor support it’ll even run
> on Windows.
>
> Arrrrgh!! I’m entirely convinced that people really just wanna do
> something DIFFERENT. It doesn’t need to be better.
>
> Well, except C#… which is clearly an improvement over C++, given that
> C++ is very obviously shit. That’s my story, and…
>
> Peter
> OSR
>
> (OTOH, I like the idea of writing drivers in Postscript even better than
> the idea of writing drivers in C#. This’ll let us write the
> documentation, and just interpret the driver at runtime. Clearly the wave
> of the future.)
>
>
> —
> 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