"class" used as a variable in C file

Discussion in 'C++' started by Sudhanshu, Jul 23, 2007.

  1. Sudhanshu

    Sudhanshu Guest

    I have a c code that uses "class" as the variable name in a function
    prototype

    I want to use this in c++ file

    How can I use it ? Any ideas

    Sudhanshu
    Sudhanshu, Jul 23, 2007
    #1
    1. Advertising

  2. Sudhanshu a écrit :
    > I have a c code that uses "class" as the variable name in a function
    > prototype
    >
    > I want to use this in c++ file
    >
    > How can I use it ? Any ideas
    >
    > Sudhanshu


    It is not guaranteed but:

    extern "C"
    {
    #define class varclass
    #include "header_with_class.h"
    #undef class
    }

    Perhaps extern "C" is enough if the compiler doesn't interpret 'class'
    in C part ?

    The best solution would be to modify the header.


    Michael
    Michael DOUBEZ, Jul 23, 2007
    #2
    1. Advertising

  3. Sudhanshu

    Default User Guest

    Michael DOUBEZ wrote:

    > Sudhanshu a écrit :
    > > I have a c code that uses "class" as the variable name in a function
    > > prototype


    > Perhaps extern "C" is enough if the compiler doesn't interpret
    > 'class' in C part ?


    No, it's not. That only controls linkage, not compilation.


    > The best solution would be to modify the header.


    Or to compile the C code to an obj file and link together, possibly
    with a C++ wrapper function.




    Brian
    Default User, Jul 23, 2007
    #3
  4. Default User a écrit :
    > Michael DOUBEZ wrote:
    >
    >> Sudhanshu a écrit :
    >>> I have a c code that uses "class" as the variable name in a function
    >>> prototype

    >
    >> Perhaps extern "C" is enough if the compiler doesn't interpret
    >> 'class' in C part ?

    >
    > No, it's not. That only controls linkage, not compilation.


    A pity.

    >> The best solution would be to modify the header.

    >
    > Or to compile the C code to an obj file and link together, possibly
    > with a C++ wrapper function.


    The problem should not be the c code but the header associated to it.

    In all cases, the C code must be compile as a C program into object file.

    Michael
    Michael DOUBEZ, Jul 24, 2007
    #4
    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. E11
    Replies:
    1
    Views:
    4,720
    Thomas Weidenfeller
    Oct 12, 2005
  2. Casey Hawthorne
    Replies:
    1
    Views:
    700
    Arne Vajhøj
    Mar 18, 2009
  3. lianliming
    Replies:
    5
    Views:
    173
    Heath Novak
    Dec 14, 2007
  4. Billy
    Replies:
    7
    Views:
    124
    Billy
    Dec 21, 2004
  5. Ted Byers
    Replies:
    23
    Views:
    413
    Peter J. Holzer
    Nov 15, 2008
Loading...

Share This Page