By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

how to solve this #define issue?

P: n/a
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".

Jul 4 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* 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".

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 4 '06 #2

P: n/a
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();
};

"Nobody" <no****@cox.net写入消息新闻:JTmqg.24334$8q.7462@du keread08...
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".

Jul 4 '06 #3

P: n/a
In article <JTmqg.24334$8q.7462@dukeread08>, no****@cox.net says...

[ ... ]
#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

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 4 '06 #4

P: n/a
* Jerry Coffin:
In article <JTmqg.24334$8q.7462@dukeread08>, no****@cox.net says...

[ ... ]
>#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?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 4 '06 #5

P: n/a
In article <4g*************@individual.net>, al***@start.no says...

[ ... ]
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).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 4 '06 #6

P: n/a
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

Jerry Coffin wrote:
In article <4g*************@individual.net>, al***@start.no says...

[ ... ]
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).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 4 '06 #7

P: n/a

"Nobody" <no****@cox.netwrote in message
news:JTmqg.24334$8q.7462@dukeread08...
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
};


>
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".

Jul 4 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.