Avoiding FunctionA/W Duplication

Jaco Greeff jaco at puxedo.org
Tue Nov 5 12:33:10 CST 2002


I would like some comments on somthing that has been bugging me quite a bit.
Implementing parts of the API can lead to duplication of code inside the
same file. In my example, let's take two functions, one operating on a ASCII
string and one one a Unicode string, let's call them "funcA" and "funcW". 

Upon implementation, the only real difference between these are the
parameters, "funcA(const char *p)" and "funcW(const WCHAR *p)". What is the
best way to keep the code maintainable and making sure that we don't have to
fix a single bug in two places in the same file? I see 3 (maybe more)
approaches:

1. Implement funcA, making funcW and exact copy with the relevant parameters
and local variables changed;

2. Implement a generic solution as a macro and get both funcA and funcW to
call it will specific parameters;

3. Do some preprosessor magic as implemented in dlls/msvcrt/scanf.[hc]

What is the general feeling as to the right way to approach this? What is
the preferred approach? (And maybe it is something I haven't listed here.) 

At this point, I've been following approach 1, which makes me a bit
uncomfortable with regardsto code bloat and forever having to make sure that
funcA is on par with funcW and vice versa. I've toyed with the idea of 2,
but as Dimitrie rightly said, it is a bit C++-ish :) (Plus it doesn't do
wonders for debugging...) Number 3, yes it works, but it can add extra
files. (Altough it almost seems the best of the 3 I've listed.)

Your comments would be appreciated, somewhere there is the best solution
that will be agreeable to all and which makes sure things stay relatively
simple. (Well, simplicity across two functions at least.)

Greetings,
Jaco




More information about the wine-devel mailing list