common var for C and C++
-
I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:
-
I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:
Put this in your .h:
#ifdef __cplusplus
extern "C" {
#endif
extern int x;
#ifdef __cplusplus
}
#endifand this in your .cpp:
#include <···.h>
int x;Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:
meirav wrote: int x; extern int x hmmmm... dont put both in the same file. file1.cpp -> declare it there :- int x; file2.c -> extern "C" int x; Try that. Nish Sonork ID 100.9786 voidmain www.busterboy.org Nish is a BIG fan of Goran Ivanisevic