Click here to Skip to main content
12,763,337 members (25,729 online)

Comments by Nemanja Trifunovic (Top 19 by date)

Nemanja Trifunovic 13-May-11 8:31am View
That's fine - just be aware that it solves a slightly different problem: converting UTF-16 to/from current system code page, which can really be anything. Internaly it uses Windows conversion API.
Nemanja Trifunovic 14-Apr-11 11:43am View
Nemanja Trifunovic 12-Apr-11 14:07pm View
Why does this question have MemoryBarrier tag?
Nemanja Trifunovic 4-Apr-11 22:50pm View
As I repeated several times: this is from ASCII to Unicode. ASCII characters are *always* < 127. Encoding detection is way beyond the scope of this little tip.
Nemanja Trifunovic 30-Mar-11 14:19pm View
The sample could be improved. std::string is guaranteed to store memory in a single block (well, at least in C++ 2011, but all current STL implementations do that anyway) so you can just reserve the string buffer with an appropriate size (which BTW needs to be done via a separate call to WideCharToMultiByte - your sample will work only for ASCII characters) and pass it directly instead of dealing with a temporary array.
Nemanja Trifunovic 30-Mar-11 14:12pm View
Reason for my vote of 5
Nice. However, be aware that your approach is not exactly equivalent to the original. CP_UTF8 means the resulting string will be UTF-8 encoded. CW2A macro converts the string to the system encoding on the user's machine.
Nemanja Trifunovic 30-Mar-11 11:07am View
Well, you said: "but when you are dealing with unicode data this doesn't work fine...". My point is that it works as described - it converts an ASCII string to a UTF-16 Unicode one (on Windows). The tip is not about best practices for developing "world-ready" software.
Nemanja Trifunovic 30-Mar-11 8:42am View
Mital, please check the title of the tip: "ASCII strings to Unicode". Of course it does not work if anything other than ASCII is stored in the source string; the point is that if you know you have only ASCII there is no way to call conversion functions - all you need to do is "widen" existing characters to.
Nemanja Trifunovic 29-Mar-11 13:14pm View
The question is tagged with C, C++. Your example is in neither of these languages.
Nemanja Trifunovic 29-Mar-11 8:58am View
Yep, very good :)
Nemanja Trifunovic 29-Mar-11 8:56am View
@Gernot: The title of my tip is clear: from ASCII to Unicode. ASCII is a 7 bit encoding and there can't be any characters > 127. If you have some other encoding of course you need to use something like MultiByteToWideChar or iconv.
Nemanja Trifunovic 28-Mar-11 10:26am View
IMHO, it is an incomplete answer. OP wants to know how to pass a multidimensional array to a function. Passing just a pointer without the size(s) is not enough.
Nemanja Trifunovic 28-Mar-11 10:24am View
It is not about style here. Because array decays into pointers when passed as function arguments, there is no way to determine the size of the array from within a function. Therefore, either the size needs to be passed as a separate parameter, or array needs to be terminated by some well-known value that the function will recognize.
Nemanja Trifunovic 27-Mar-11 17:06pm View
It is not a good idea to hardcode the array size within the function. It is better to pass it as another parameter instead.
Nemanja Trifunovic 16-Mar-11 22:22pm View
In my sample, it is the derived classs that is instantiated and it does not have any virtual functions.
Nemanja Trifunovic 17-Feb-11 10:45am View
You can distribute the dll's even without the redistributable package - the difference is, depending on the version of VC++ (or even Windows?) you need to supply a manifest file together with the dlls.
Nemanja Trifunovic 27-Dec-10 10:34am View
Microsoft replaced the Intellisense C++ compiler completely and the new one was not ready for C++/CLI in time for VS2010.
Nemanja Trifunovic 30-Sep-10 11:30am View
It would be interesting to add that early in C++ days there was no delete[] version, and plain delete was supposed to be used to clean up both after new and new[]. Of course, one should not assume that it would be OK to do such a thing nowdays.
Nemanja Trifunovic 25-May-10 11:58am View
This is a correct answer. References are in practice implemented as pointers, but that is just an implementation detail. A reference is really an alias.
As I stated in my answer

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 1 Jan 1900
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid