"class" used as a variable in C file

S

Sudhanshu

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
 
M

Michael DOUBEZ

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
 
D

Default User

Michael said:
Sudhanshu a écrit :
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
 
M

Michael DOUBEZ

Default User a écrit :
No, it's not. That only controls linkage, not compilation.

A pity.
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top