| | |
Preventing code from using code
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
test.h
code.c
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
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
C Syntax (Toggle Plain Text)
#define _MAIN_ #include "test.h" int main(){ fcn1(); fcn2(); return 0; }
test.h
C Syntax (Toggle Plain Text)
#ifdef _MAIN_ void fcn1(); #endif #ifndef _MAIN_ void fcn2(); #endif
code.c
C Syntax (Toggle Plain Text)
#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
Last edited by venomxxl; Jan 23rd, 2009 at 7:38 pm.
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).
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
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.
I'm thinking you're meaning static.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
•
•
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).
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.
•
•
•
•
Originally Posted by MosaicFuneral
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.
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.
Last edited by venomxxl; Jan 24th, 2009 at 7:07 am.
![]() |
Similar Threads
- Send data on a serial port (C++)
- code tags (DaniWeb Community Feedback)
- ASP: Deleting a file (ASP)
- specifying home dir (PHP)
- Looking for C++ Source Code for Preventing Hooks (C++)
- New Problem with input output in Tk (Python)
- Inserting array into cookie (PHP)
- How to be Crash Free (C++)
- Preventing Hooks (C++)
Other Threads in the C Forum
- Previous Thread: linking of .c and .h files
- Next Thread: How to clear the character in the file???
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation overwrite owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






