I'm not sure what you are trying to accomplish, but that header file is really unnecessary. Both functions are coded in code.c and the header file will not prevent that. But you should get an error in main.c because fcn2() was not declared (because ifdef'ed out in the header file).
Yes, I expected to get an error, but didn't get one.
What I'm trying to accomplish:
"What I'm trying to do is to prevent some code using functions in a header."
It may be lacking something like "(...)prevent some code using some of the functions(...)", but I thought it would be enough for an explanation.
You mean like the keyword static, to keep it from external linkage; or volatile to keep the compiler from messing with it?
I'm thinking you're meaning static.
Might be, I tried using it in the header and what I got was what I wanted to get:
main.c:(.text+0x17): undefined reference to `fcn2'
But I also got:
test.h:3: warning: ‘fcn2’ used but never defined
Which doesn't solve my problem.
Some further words of explanation:
My application actually calls function using the name of function in user's input. It's like a command prompt of sorts. So I expect to get that error when the application is running, not on compilation like the test application does. But it's like a "good error"
If the explanation is lacking something important please tell me what.