As a highly-experienced programmer, I would offer that device drivers are
the most demanding of all forms of programming one can engage in. Silly
errors turn the screen blue. My productivity as an app programmer was
measured in close to 200 lines of code per hour. In writing drivers, I
considered that writing at an order of magnitude less meant I was coding
far too fast and making stupid mistakes. Even more experienced driver
writers claimed that 20 lines per day was doing pretty well, except on the
days of negative productivity (adding lines that were in error and had to
be corrected/removed). I taught drivers for many years, and I believe the
word “gobsmacked” defines the reaction of app programmers coming into the
kernel. It is a very different form of reality from app programming. In
my set of “simple rules for newbies”, one of them was “forget the CRT
exists”. Yes, it is another of my overkill rules, but like most of them,
by the time you learn the truth, you are experienced enough to understand
how much of the truth is really true. Expecting that “tolower” is going
to work on Unicode means a level of inexperience that is downright
dangerous. It is dangerous in app space, and more so in kernel space.
When I teach app-level programming, the students are dismayed when I tell
them that their favorite upper-lo-lower-case hack of adding 0x40 to
characters in the range [A-Z] is hopelessly outdated. They don’t like
calling a subroutine because we all know that calling a subroutine is
expensive, so let’s do the code right in-line. We don’t need no stinkin’
subroutines. Then I explain that you can’t use strcmp, or lstrcmp, or any
of those trivial comparison routines to get proper collating sequence.
Oh, wait. If you have to do it, use lstrcmp, which is locale-sensitive.
On a good day. With a tail wind. But if you really care, use the
CompareString API.
Sadly, one of the critical languages has been omitted from the locales:
“ALA filing rules”. As in Americal Library Association. This locale has
very specific things to say about how accented characters sort with
unaccented characters, for example. I know this because I had to
implement an “ALA” collating sequence routine for 8-bit characters Back In
The Day, and I have looked at what it would take for Unicode, and it is
somewhere along the complexity of Chhinese. Folks who implement library
systems can take the time to do an ALA collating sequence subroutine that
can cover 90% of the rules just by transforming accented characters into
unaccented characters, but can’t handle “Mc” sorting equal to “Mac” when
those appear as the beginning of surnames, and a ton of other “corner
cases” I once knew (my SO was a librarian for nearly 40 years, before she
became a professor in the school of library science).
Note that the way tolower works is probably by adding 0x40 (32) to the
8-bit value if the 8-bit value passes the isalpha() test. I am not near
my Unicode book, but I suspect that in Greek and other alphabets that have
the concept of upper and lower case, that doing isalpha() on the low-order
8 bits is used as the predicate, and only the low-order 8 bits define the
character offset within the Unicode segment, so adding 0x40 probably is
sufficient for those languages. But in The Character Set Formerly Known
As ISO-8859-1 (Latin 1), the accented characters are not 0x40 from their
lower case counterparts. So life gets a bit more complex.
The kernel is not app space. There is a lot of the C-standard CRT that
does not exist in the kernel version of the “CRT”, and knowing which part
is there, or has slightly different semantics, is not something you want
newbies to the kernel to discover empirically. Unless, of course, you
like the color blue.
joe
Alright I was going to stay out of this nonsense, but the fact is that
there is limited support for C runtime routines in the OS. It is not
forbidden. The calls that are forbidden are marked deprecated.
The OP thought he found a bug in Windows when he actually had a silly
programmer on device error. That was humiliating enough without the STERN
LECTURES that more or less commanded him to give up, go away, never
compile
another line of code again.
Mark Roddy
On Sun, Nov 24, 2013 at 1:13 AM, wrote:
>
>> > I repeat what I said before, only more strongly: the only way to
>> correctly use the CRT in the
>> > kernel is to not use it at all. If you want to use the CRT, write user
>> apps.
>>
>> Well,I would put it even more strongly(perhaps harshly) - if you want
>> to
>> use the CRT in the kernel
>> you are simply not qualified for system-level programming, because you
>> don’t understand why UM libraries cannot be used by the KM code…
>>
>>
>>
>> Anton Bassov
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> 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
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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