I want to use local .h file for define same names used in my lib. My lib has a default value definition for this names, but I'd like change this default value using local .h file. However, I'm having unwanted behaviour. How can I solve this?
test.c
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "conf.h"
#include "mylib.h"
int main ()
{
printf("Value in main: %d\n", NAMEDEFINITION);
fn();
return 0;
}
conf.h
#define NAMEDEFINITION 42
mylib.h
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#ifndef NAMEDEFINITION
#define NAMEDEFINITION 84
#endif
void fn();
mylib.c
#include "mylib.h"
void fn()
{
printf("Value in fn: %d\n", NAMEDEFINITION);
return;
}
My compiling line and output:
user@local:~/user/test/c$ gcc test.c mylib.c -o test
user@local:~/user/test/c$ ./test
Value in main: 42
Value in fn: 84
[EDITED]
I'd like NAMEDEFINITION be "42" when I define it in conf.h, then print "42" in two main() calls. When it is not defined in conf.h, it would be its default value, "84" (print "84" in two main() calls.