how to solve this #define issue?

Discussion in 'C++' started by Nobody, Jul 4, 2006.

  1. Nobody

    Nobody Guest

    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".
    Nobody, Jul 4, 2006
    #1
    1. Advertising

  2. * 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?
    Alf P. Steinbach, Jul 4, 2006
    #2
    1. Advertising

  3. Nobody

    mos Guest

    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" <> дÈëÏûÏ¢ÐÂÎÅ: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".
    >
    >
    >
    mos, Jul 4, 2006
    #3
  4. Nobody

    Jerry Coffin Guest

    In article <JTmqg.24334$8q.7462@dukeread08>, 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.
    Jerry Coffin, Jul 4, 2006
    #4
  5. * Jerry Coffin:
    > In article <JTmqg.24334$8q.7462@dukeread08>, 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?
    Alf P. Steinbach, Jul 4, 2006
    #5
  6. Nobody

    Jerry Coffin Guest

    In article <>, 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.
    Jerry Coffin, Jul 4, 2006
    #6
  7. Nobody

    Amit Guest

    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 <>, 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, Jul 4, 2006
    #7
  8. Nobody

    Jim Langston Guest

    "Nobody" <> 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".
    >
    >
    >
    Jim Langston, Jul 4, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    450
    Thomas Matthews
    Feb 19, 2004
  2. robin liu
    Replies:
    3
    Views:
    810
    Robin Liu
    Apr 21, 2006
  3. Kai Kuehne
    Replies:
    0
    Views:
    286
    Kai Kuehne
    Jul 2, 2007
  4. Prabahar
    Replies:
    2
    Views:
    749
    Prabahar
    Oct 21, 2007
  5. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    446
    Brian Takita
    Jan 23, 2006
Loading...

Share This Page