Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dymanically using a header file

Status
Not open for further replies.

delci

Instructor
Jul 13, 2005
4
GR
Hi,

I have the following question.
In my C code, I read information from a text file dynamically, which gives me information about another file (which is a header file), its path.
The problem is that I cannot use this header file, since I cannot include it in the declaration, since I have to read the information dynamically.

Is there a way to do that in C?
Thanks in Advance for the help.
 
If dynamically means at run-time, your compiled (of course;) program does not know anything about header files (compile-time thing;).
Of course, you cannot include it in the declaration because of no any declarations (and sources) at run-time.
 
That being said -- at compile time you can optionally chose to include or exclude certian headers (often used for making the same program compile under multipule platforms) by using preprocessor directives.

at run time the best you can do is have the program generate source for another program and compile it (a technique common to genetic programming algos).

[plug=shameless]
[/plug]
 
Hi,

Thanks for the replies.
I would like to know what can be done in case that the file is not a header file but a .c file.

Please help,
Delci
 
It's better to tell us what do you want...
 
ok,

here is what I want to do.
I have a .c file which has the filenames and path for some
other .c files.
The first .c file should make a call to the other .c files and pass to
them parameters for their execution.

The other thing is that these two files must exchange information.

How can I do these things?
thanks,

delci.
 
Alright? So, why not just

#include "somefile.c
or better
#include "somefile.h"

Why must the linking of the file be conditional? What functions from that file you actually call is up to you.

[plug=shameless]
[/plug]
 
Let's dot our 'i's'. C-language executable unit is a program, not a file. Sources of the program may contain one or more source modules (text files in most of C implementations, but it's not C language mandatory demand).

So .c file can't make a call to the other .c files because of it's C function only make a call to another C functions (but not source files!).

 
I'm still not sure I get what he's really asking for, so I'm going to ask a host of questions:

1.) Why not just make a header(s) and include the files, and then compile everything together?
2.) Why must it be "dynamic" and do mean "dynamically linked" as in shared objects or "linked on the fly"?
3.) I think what your trying to do is similar to loading a plugin or shared object file based on the fact you said, "since I cannot include it in the declaration, since I have to read the information dynamically." This would be like loading a plugin to application -- is this the sort of thing your trying to do?

If so, .so files are compiled objects, and there are threads about using .so in this and other forums already.
4.) "not a header file but a .c file." A c file is text -- compile it into an object, link it into the program at compile time -- OR compile it to a shared object and read about how to use them.

Some sample code of what you are thinking, or better a description of what the program should do would go along ways toward us being able to offer a path to a solution.

[plug=shameless]
[/plug]
 
The other thing is that these two files must exchange information.

"extern " -> maybe, if my mind reading skills are
what they used to be.

kinda hard to make out exactly what he means.

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top