Re: How many bytes per Italian character?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 06 Apr 2007 11:41:47 -0400
See below...
On Fri, 6 Apr 2007 22:33:53 +0900, "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote:
"MrAsm" <mrasm@xxxxxxx> wrote in message****
news:tm7c13dfq7b973pll4d1refk3f567uebuo@xxxxxxxxxx
On Fri, 6 Apr 2007 17:15:56 +0900, "Norman Diamond"
<ndiamond@xxxxxxxxxxxxxxxx> wrote:
My value in the registry is a string, "COM6", 5 characters long:[...]
C O M 6 nul
How many bytes does this need? Let's ask Windows CE 5. Better not do
this too soon after eating though.
dwRegQueryValueExBug has value ERROR_MORE_DATA.
dwType has value REG_SZ.
dwSize has value 20.
szBuffer contains 5 characters: C O M 6 nul
So, do they use UTF-32 internally, so each character is 4 bytes, and we
have 5*4 = 20 bytes?
Even if they do, why would the result try to store 20 bytes?
If you ask how big the value needs to be,(buffer pointer of NULL), it gives you a value.
You allocate that amount of space. That gives the correct size buffer.
****
But this would be a very strange thing: where is that documented?
The part of MSDN which is 75% accurate is the part which is documented. No
one knows the accuracy rate of the part which isn't documented.
Actually, the issue of "accurate" is not the same as "complete". And there are days I
think 75% is high for "complete"
****
****
Should the programmer be a "Sherlock Holmes"??
That is unavoidable. I think you already know that.
And moreover why the final buffer contains just the 5 chars?
Good question. I assumed that the final buffer contains just the 5 wchar_ts
because I only provided that much space. I passed a parameter saying 10
bytes (10 chars in C/C++ speak). But how do we know whether the API
overwrote an additional 10 bytes of my memory? It returned ERROR_MORE_DATA
and a count of 20, so how do we know what else it did? Yeah, good question.
10 bytes is not 10 characters in C/C++ speak. 10 bytes is 10 bytes. Characters are an
interpretation of bytes, but the Registry APIs work in terms of bytes. 'char' is a
misnomer, because it really is 'signed byte', and should not bethought of in any speak as
meaning 'character' unless the discussion is qualified with a discussion of the size of
'character'.
****
***But who is doing the coding in Microsoft??
You must be new here.
They sometimes seem very "picky" in hiring people, and these are the
results???
Picky based on corporate needs not based on quality needs.
My own issue is that there is not enough adult supervision. New programmers make
beginner's mistakes, but nobody is providing training or oversight. The quality of some
of the code I've seen would result in an 'F-' grade if I were teaching a course in which
it was an assignment, yet it makes it into products!
I spent a lot of years teaching new programmers, especially new hires in a commercial
product environment. They take a LOT of effort to train properly. Essentially, training
became a full-time job when I had 5 junior programmers. I had to do not only technical
training, but also attitude training (it doesn't matter if "it works"; it has to work
robustly, be maintainable, be clearly documented, etc. It has to be modular, obey proper
design patterns, and be readable by at least one other programmer on the team. We were
doing several hours of code review per week, myself, one senior programmer, and one junior
programmer. We were finding bugs, design flaws, buffer overruns, etc. on each review.
Scary. And it was largely because junior programmers are too trusting, both of their own
code and their input parameters. It doesn't matter if the interfaces are clean, as long
as the code computes the correct result (circular dependencies are fine, global variables
are fine, pointers to everything in sight are fine, as long as it compiles and runs and
produces the correct result with the one test case that has been presented).
I do not see nearly enough oversight of the junior programmers there. And an abysmal
example like the recent one I found in the MSDN (and the number of bugs I've found in
others) suggests there is no review of these, either.
Quality doesn't happen, it is created. And that takes a LOT of work.
****
*****
BTW: If these routines were open source, we could see the code ourselves
and fix these blunders ourselves.
Oh yeah, part of Windows CE _is_ open source. Last year I found a bunch of
garbage relating to StringCchPrintf. If I have time I should look to see if
RegQueryValueEx has visible source.
StringCchPrintf is not part of the OS. It is a header file which is just a user level
interface.
The myth of open source is that you can fix all the bugs yourself. So suppose you fix the
:"bug" (who says you didn't introduce six new ones in the process?) You now have an app
that runs only on YOUR copy of the OS. So you have to distribute your copy of the OS to
the end users. And they have to integrate this copy with their other copies that have
different bug fixes. And what if your fix conflicts with someone else's fix?
I do not consider this a viable approach to product development. Perhaps you never had to
produce code that ran on multiple versions on Unix, where each vendor "fixed" the bugs and
utilities. It was as close to hell as I hope to ever see. I later worked for an
organization that had code that ported to 30 Unix platforms, and I had to maintain some of
the code. Any change had to be regression-tested on all 30 platforms, because it might
not compile, or the compiler might generate bad code, or the runtime library might do the
wrong thing, or the kernel might do something different. ARGH!
And in this case it is even stranger, since there is no harm in allocating slightly more
space than is required.
joe
*****
Joseph M. Newcomer [MVP]
PS: Is there a netiquette here about cross-posting messages to different
newsgroups? What are the rules? Thanks.
Surely netiquette calls for not multi-posting and I didn't multi-post. I
think my cross-posting was pretty reasonable. International because this
wasn't the Japanese version, and Windows CE because that's the platform
involved. But wait, how did MFC get added on?
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: How many bytes per Italian character?
- From: Norman Diamond
- Re: How many bytes per Italian character?
- From: MrAsm
- Re: How many bytes per Italian character?
- Prev by Date: Re: To get the SetTimer identity
- Next by Date: Re: How many bytes per Italian character?
- Previous by thread: Re: Using TaskDialogIndirect is Causing an Access Violation in MFC
- Next by thread: Re: How many bytes per Italian character?
- Index(es):
Relevant Pages
|