Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   how to solve this #define issue? (http://www.velocityreviews.com/forums/t455142-how-to-solve-this-define-issue.html)

Nobody 07-04-2006 05:19 AM

how to solve this #define issue?
 
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".




Alf P. Steinbach 07-04-2006 05:25 AM

Re: how to solve this #define issue?
 
* 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?

mos 07-04-2006 05:25 AM

Re: how to solve this #define issue?
 
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" <nobody@cox.net> 写入消息新闻: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();
> };
>
> 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".
>
>
>




Jerry Coffin 07-04-2006 05:25 AM

Re: how to solve this #define issue?
 
In article <JTmqg.24334$8q.7462@dukeread08>, nobody@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.

Alf P. Steinbach 07-04-2006 05:35 AM

Re: how to solve this #define issue?
 
* Jerry Coffin:
> In article <JTmqg.24334$8q.7462@dukeread08>, nobody@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?

Jerry Coffin 07-04-2006 05:57 AM

Re: how to solve this #define issue?
 
In article <4gud1jF1pdi1cU1@individual.net>, alfps@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.

Amit 07-04-2006 01:37 PM

Re: how to solve this #define issue?
 
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 <4gud1jF1pdi1cU1@individual.net>, alfps@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.



Jim Langston 07-04-2006 02:32 PM

Re: how to solve this #define issue?
 

"Nobody" <nobody@cox.net> wrote 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".
>
>
>





All times are GMT. The time now is 02:50 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.