K
karthikbalaguru
Hi,
I have a Macro defined in the header file. This header file is being
used
in all the C files of my project . I undefined a Macro in one of the C
file and
tried to check if its status is undefined in another C file. But, it
appears to
be in defined status.
I understand that ' An identifier defined with #define is available
anywhere in
the source code until a #undef is reached.'. So, here in the
second file, though the header file has the #define, the #undef done
in my first file has not had any influence on the second file as there
is no real #undef in the second file after the #define.
How to make it appear undefined in another C file also ?
Any tricks ?
In short, how to make an #define'd value behave like a global variable
so that if it is undefined in one file, it is available as undefined
in
another file also ?
Below is a snapshot of dummy code for your reference -
mydefines.h
------------------
#define VERSION_1
void checkversionstatus(void);
dummy.c
--------------
#include <stdio.h>
#include "mydefines.h"
int main()
{
int i = 1;
if (1==i) {
#undef VERSION_1
}
#ifdef VERSION_1
printf(" VERSION_1 is defined \n");
#else
printf(" VERSION_1 is NOT defined \n");
#endif
checkversionstatus();
return 0;
}
dummy1.c
----------------
#include <stdio.h>
#include "mydefines.h"
void checkversionstatus(void) {
#ifdef VERSION_1
printf(" VERSION_1 is defined \n");
#else
printf(" VERSION_1 is NOT defined \n");
#endif
}
When i compile and execute the above code , i get the below output :-
VERSION_1 is NOT defined
VERSION_1 is defined
How to get an output as below ?
VERSION_1 is NOT defined
VERSION_1 is NOT defined
Thx in advans,
Karthik Balaguru
I have a Macro defined in the header file. This header file is being
used
in all the C files of my project . I undefined a Macro in one of the C
file and
tried to check if its status is undefined in another C file. But, it
appears to
be in defined status.
I understand that ' An identifier defined with #define is available
anywhere in
the source code until a #undef is reached.'. So, here in the
second file, though the header file has the #define, the #undef done
in my first file has not had any influence on the second file as there
is no real #undef in the second file after the #define.
How to make it appear undefined in another C file also ?
Any tricks ?
In short, how to make an #define'd value behave like a global variable
so that if it is undefined in one file, it is available as undefined
in
another file also ?
Below is a snapshot of dummy code for your reference -
mydefines.h
------------------
#define VERSION_1
void checkversionstatus(void);
dummy.c
--------------
#include <stdio.h>
#include "mydefines.h"
int main()
{
int i = 1;
if (1==i) {
#undef VERSION_1
}
#ifdef VERSION_1
printf(" VERSION_1 is defined \n");
#else
printf(" VERSION_1 is NOT defined \n");
#endif
checkversionstatus();
return 0;
}
dummy1.c
----------------
#include <stdio.h>
#include "mydefines.h"
void checkversionstatus(void) {
#ifdef VERSION_1
printf(" VERSION_1 is defined \n");
#else
printf(" VERSION_1 is NOT defined \n");
#endif
}
When i compile and execute the above code , i get the below output :-
VERSION_1 is NOT defined
VERSION_1 is defined
How to get an output as below ?
VERSION_1 is NOT defined
VERSION_1 is NOT defined
Thx in advans,
Karthik Balaguru