Hello,
I had no idea which title I should have chosen. Anyway, I'll try to explain my problem.
What I'm trying to do is to prevent some code using functions in a header. This problem causes invulnerabilities in my application. I made a test program to show what exactly I'm trying to do. I think it's called macros, but I have no idea if what I'm doing is good, I read some tutorials on macros, but it didn't work.
I'm using Linux and GCC 4.2.4.
main.c
#define _MAIN_
#include "test.h"
int main(){
fcn1();
fcn2();
return 0;
}
test.h
#ifdef _MAIN_
void fcn1();
#endif
#ifndef _MAIN_
void fcn2();
#endif
code.c
#include <stdio.h>
#include "test.h"
void fcn1(){
printf("No problem, you can enter here.\n");
}
void fcn2(){
printf("Who let you in here?!\n");
}
Commands:
gcc -c main.c
gcc -c code.c
gcc main.o code.o -o test
Output:
No problem, you can enter here.
Who let you in here?!
What I want to know:
- Are macros enough to solve this problem?
- Are there any mistakes in the way I use macros?
- What might be a solution to this problem? (if macros aren't enough to solve this problem)
Thanks for your help.
-Marek