|
From: Per W. <pw...@ia...> - 2005-05-18 19:46:11
|
No, building null-separated character arrays using strxxx() functions
isn't non-standard. And the SHFileOperation() function isn't alone to make
use of this concept. Win32 have a quite large number of functions with
this interface.
However, null-separated character arrays have been used for parameter and
environment passing etc. since the C language was invented, and probably
in similar forms since long before.
It is 100% within the standard and 100% portable, even if it might be
slightly less than common to use. The same code is also directly portable
to wchar_t with corresponding changes to wcscpy(), wcscat(), ...
If you think about it: the normal use of strcat() is to replace the '\0'
at the end of the first string with a new null-terminated string. But when
the need is there, you are fully free to keep this extra '\0' in the
middle. printf() won't be able to print the string, but that is besides
the point. A character array is only a null-terminated text string if I as
programmer chooses to treat it like one.
That is why a lot of people uses variable names like lpz to specifically
clarify that _they_ treat the data as a zero-terminated text string, and
not an array of characters or bytes.
One of the main advantages of a language such as C is the opportunities to
make best use of the available tools. On the other hand, that is also one
of the biggest disadvantages with the language - a dummy can blow his/her
foot off without noticing the danger ;)
/Per W
On Wed, 18 May 2005 Mat...@Ve... wrote:
> I didn't call the str functions nonstandard.
> I called your particular use of them nonstandard.
>
> --Matt
>
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of Per
> Westermark
> Sent: Wednesday, May 18, 2005 11:11 AM
> To: Guillermo Gutierrez
> Cc: Mat...@Ve...;
> dev...@li...
> Subject: RE: FW: [Dev-C++] Win32 Shell API
>
>
> Calling strxxx() functions non-standard sounds a bit amusing given the
> fact that they are part of a large number of standards and also used in
> multidigit billion lines of code...
>
> Anyway, yes std::string works perfectly well to use.
>
> std::string s;
> std::string separator;
>
> separator.append("\0",1);
>
> s += "file1.txt";
> s += separator;
> s += "file2.txt";
> s += separator;
> ...
>
> const char* psz = s.c_str();
>
> /Per W
> ___________________________________________________________________
> The information contained in this message and any attachment may be
> proprietary, confidential, and privileged or subject to the work
> product doctrine and thus protected from disclosure. If the reader
> of this message is not the intended recipient, or an employee or
> agent responsible for delivering this message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify me
> immediately by replying to this message and deleting it and all
> copies and backups thereof. Thank you.
>
|