I am trying a global variable to hold my error message in C.
One library called Utils has:
#ifndef private_error_h
#define private_error_h
extern char error[1024];
__declspec(dllexport) void FillError(char* newError);
#define GetErr() error
#endif
File error.c:
#include "private_error.h"
char error[1024];
void FillError(char* newError) {
// ...
}
Then I try to use it in a program:
#include "private_error.h"
int main() {
FillError("General error");
printf("%s\n", GetErr());
return 0;
}
It creates two variables with different addresses. How can I make the program use the variable from the Utils library?
I did manage to bypass this problem by changing GetErr to a function returning the string, but I am still wondering where the error is here.