On 2020-01-14 01:13, JJ Merelo wrote:
Never miss a good chance to bash documentation...
Guilty as charged?
By the way, "C String" REQUIRES a nul at the end:
an error in the NativeCall documentation.
No, it does not. And even if it did, it should better go to the C, not
Raku, documentation
Oh Great And Mighty Gatekeeper of the Documentation!
You are in error. The problem is the mistake in the
documentation you won't fix and your misunderstand of
the C programming language.
INTERNATIONAL STANDARD ©ISO/IEC ISO/IEC 9899:201x
Programming languages — C
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
5.2.1 Character sets
:
2 In a character constant or string literal, members
of the execution character set shall be
represented
by corresponding members of the source character
set or by escape
sequences consisting of the
backslash \ followed by one or more characters.
A byte with
all bits set to 0, called the null
character, shall exist in the basic execution
character set; *it
is used to terminate a character
string*.
7.1.1 Definitions of terms
1 A string is a contiguous sequence of characters
*terminated by and including the first null
character*. The term multibyte string is
sometimes used instead to emphasize special
processing given to multibyte characters contained
in the string or to avoid confusion
with a wide
string. A pointer to a string is a pointer to
its initial (lowest addressed)
character. The
length of a string is the number of bytes
preceding the null character and
the value of a
string is the sequence of the values of the
contained characters, in order.
You are basically confusing a "String" with a "String literal".
They are two different things. A String Literal can have
nuls in them that are part of the string literal. And
with a string literal, you have to also keep track of the
length of the string literal.
In WinAPI, calls
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regsetvalueexw
a "string literal" is annotated as:
const BYTE *lpData
And the byte count of such is
DWORD cbData
Note that "*lpData" can be a little endian four byte
DWORD cardial or a UTF16 array of WORDS.
A "C" string (not a string literal) would be
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
LPCWSTR lpValueName
Are you able to see the difference between "const BYTE *lpData
plus DWORD cbData" and "LPCWSTR lpValueName"? One is
a "String Literal" and the other one is "String".
"LPCWSTR lpValueName" does not need to know the length of the string
because it expects to see a nul at the end.
Your holding on to NOT-A-BUG will mean that everyone
using the documentation will have to figure this all
out the hard way, as I did.
Oh great and exalted Gatekeeper, today you get a C-.
Minus for meanness.
Your favorite Golden Retriever,
-T