how to solve this #define issue?

N

Nobody

Anyone have a clean way of solving this define issue?

In Windows, there are sometimes unicode functions and multibyte functions...
the naming convention used is FunctionA for multibyte and FunctionW for
unicode...

So basically what happens is:

void FunctionA();
void FunctionW();

#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

now I have a class...

class Whatever
{
public:
void Function();
};

obviously this gets mapped to either FunctionA or FunctionW, which I dont
want...

I want *my* function to be called "Function", but be able to call FunctionA
or FunctionW with in my code...

Also if someone calls my library, to be able to call "Function" without
loosing the ability of the Windows "Function" macro...

Is there any way to solve this cleanly without undefing "Function" for the
whole project?

I can't even rename my "Function" to anything close without totally going
"stupid" like "Funktion".
 
A

Alf P. Steinbach

* Nobody:
Anyone have a clean way of solving this define issue?

In Windows, there are sometimes unicode functions and multibyte functions...
the naming convention used is FunctionA for multibyte and FunctionW for
unicode...

So basically what happens is:

void FunctionA();
void FunctionW();

#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

now I have a class...

class Whatever
{
public:
void Function();
};

obviously this gets mapped to either FunctionA or FunctionW, which I dont
want...

I want *my* function to be called "Function", but be able to call FunctionA
or FunctionW with in my code...

Also if someone calls my library, to be able to call "Function" without
loosing the ability of the Windows "Function" macro...

Is there any way to solve this cleanly without undefing "Function" for the
whole project?

I can't even rename my "Function" to anything close without totally going
"stupid" like "Funktion".

Naming convention. Call your function "function", not "Function".
 
M

mos

Hi!

Just copy the windows's define before your class. thus:

//class Whatever.h

#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

class Whatever
{
public:
void Function();
};
 
J

Jerry Coffin

[email protected] says... said:
#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

[ ... ]
I want *my* function to be called "Function", but be able to call FunctionA
or FunctionW with in my code...

I don't know whether you consider it very clean or not, but if you
enclose its name in parentheses, the name won't be expanded as a
macro:

(Function)(args); // calls your Function
Function(args); // calls their FunctionA or FunctionW
 
A

Alf P. Steinbach

* Jerry Coffin:
[email protected] says... said:
#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

[ ... ]
I want *my* function to be called "Function", but be able to call FunctionA
or FunctionW with in my code...

I don't know whether you consider it very clean or not, but if you
enclose its name in parentheses, the name won't be expanded as a
macro:

(Function)(args); // calls your Function
Function(args); // calls their FunctionA or FunctionW

The following program,

#define FOO foo

void foo() {}

int main()
{
FOO();
(FOO)();
}

compiles fine with a number of compilers, including Comeau Online.

Hence, I wonder if you have standard chapter-&-verse id's?
 
J

Jerry Coffin

[email protected] says... said:
The following program,

#define FOO foo

void foo() {}

int main()
{
FOO();
(FOO)();
}

compiles fine with a number of compilers, including Comeau Online.

Hence, I wonder if you have standard chapter-&-verse id's?

Thinking about it, what I said doesn't apply in this case.

In the case of a function-like macro, the name must be followed
immediately by a left-paren to be expanded as a macro. Unfortunately,
even though they're names of functions, they're using object-like
macros instead of function-like macros in this case.

So, for the trick I cited to work, you'd have to do the defines
something like:

#ifdef UNICODE
#define Function(x) FunctionW(x)
#else
#define Function(x) FunctionA(x)
#endif

As far as chapter and verse, 16.3/9 is what applies (in the correct
situation).
 
A

Amit

the other way might be to provide concrete implementation for
FunctionA()
& FunctionW()

Now on calling fuction() from your application code, it will call the
exact function based on your application project setting.

-Amit
 
J

Jim Langston

Nobody said:
Anyone have a clean way of solving this define issue?

In Windows, there are sometimes unicode functions and multibyte
functions... the naming convention used is FunctionA for multibyte and
FunctionW for unicode...

So basically what happens is:

void FunctionA();
void FunctionW();

#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif

now I have a class...

class Whatever
{
public:
void Function();
};
class Whatever
{
public:
#undefine Function
void Function();
#ifdef _UNICODE
#define Function FunctionW
#else
#define Function FunctionA
#endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top