I’ve got a program where I’m forced to meld together some C and C++ code. I’ve got some global variables defined in C and I need to access them in both C and C++ files but can’t figure it out. Here’s what I have, which works in C files, but not in CPPs:
C.h
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _COMMON_H_
#define _COMMON_H_
extern char test[100];
#ifdef __cplusplus
}
#endif
C.c
#include <windows.h>
#include <stdio.h>
#include "C.h"
char test[100] = "value";
CPlusPlus.cpp
#include "C.h"
int TestFunction() {
// I need to access variable test here
}
Thanks,
Ben
Like this: