S
Seung-Uk Oh
Hi, everyone!
We are developing an application using both C and C++.
We have defined a structure in a C program as follows:
typedef struct node {
struct node *next;
int value;
}List;
And we construct a linked list using the above structure.
Then we pass the linked list to a function which is defined
in a C++ program enclosed with "extern "C" { }".
e.g.)
IN C-program
typedef struct node {
struct node *next;
int value;
}List;
int main(){
List *l;
/* l is initialized */
function_in_cpp(l);
}
IN C++-program
extern "C" {
typedef struct node {
struct node *next;
int value;
}List;
function_in_cpp(List *l)
{
....
}
}
When the length of a linked list is 1, the function call to
a function in a C++ is successful. However, when we call the function
in C++ program with the linked list whose length is 2, the actual
parameter in the C++ program is NULL. So, we can't pass the desired
value to a function in the C++ program.
Is there any difference between C and C++ in representing a "struct"
type variable? If any, the difference results in the consequence?
Please anybody help me.
Thanks in advance
We are developing an application using both C and C++.
We have defined a structure in a C program as follows:
typedef struct node {
struct node *next;
int value;
}List;
And we construct a linked list using the above structure.
Then we pass the linked list to a function which is defined
in a C++ program enclosed with "extern "C" { }".
e.g.)
IN C-program
typedef struct node {
struct node *next;
int value;
}List;
int main(){
List *l;
/* l is initialized */
function_in_cpp(l);
}
IN C++-program
extern "C" {
typedef struct node {
struct node *next;
int value;
}List;
function_in_cpp(List *l)
{
....
}
}
When the length of a linked list is 1, the function call to
a function in a C++ is successful. However, when we call the function
in C++ program with the linked list whose length is 2, the actual
parameter in the C++ program is NULL. So, we can't pass the desired
value to a function in the C++ program.
Is there any difference between C and C++ in representing a "struct"
type variable? If any, the difference results in the consequence?
Please anybody help me.
Thanks in advance