On 05 Nov 2002 13:42:15 -0500, Vincent BĂ©ron vberon@mecano.gme.usherb.ca wrote :
From what I saw in a couple of places: from funcA, do some magic on the parameters (convert to Unicode), then call funcW, then reconvert the result from Unicode to ASCII. Yes you have to convert twice, but you use the same function.
I'm happy with that and will call it option 4. It will work in a large number of cases, hence the large number of places it has been used in. (I really don't know why I left it out, but is is problably because I tought about the following: I'm wondering about the case where it (option 4) won't work, let's say we have,
void funcA(char ch) { WriteFile(h, &ch, sizeof(char), &num, NULL); }
and
void funcW(WCHAR ch) { WriteFile(h, &ch, sizeof(WCHAR), &num, NULL); }
If we do the char -> WCHAR conversion, we will end up writing sizeof(WCHAR) bytes for every single character. In this simplest case, we could define a macro,
#define WRITE_CH(ch, type) WriteFile(h, &ch, sizeof(type), &num, NULL)
and this can be used in the functions,
void funcA(char ch) { WRITE_CH(ch, char); }
and
void funcW(WCHAR ch) { WRITE_CH(ch, WCHAR); }
In the case of similar bigger/longer functions, writing the macro is problably not the right thing to do. And this is where I end up duplicating code, eek.
Greetings, Jaco
In the case of similar bigger/longer functions, writing the macro is problably not the right thing to do. And this is where I end up duplicating code, eek.
this has been discussed zillions of times before duplicating the code (in that case) is one solution (in your example, you could use a shared function between A & W familly, using as parameters 1/ a pointer to a memory zone to write from 2/ the length to be written
A+
On November 5, 2002 02:14 pm, Jaco Greeff wrote:
In the case of similar bigger/longer functions, writing the macro is problably not the right thing to do. And this is where I end up duplicating code, eek.
The macro idea is almost always wrong, sorry! :) For these sort of cases, the Option 5 listed in my other email on this topic should work just fine.