tags:

views:

227

answers:

3

If i have a string formatting program in C, that consits of only one file, is it possible to find where that file resides in memory and let the running program process its own source file? In other words, when a C program runs, is it possible to define a pointer that points to the actual code, and process that? Not sure if that makes sense, if it doesnt, let me know and I will edit. I dont want to open and read the source file, but do it from memory.

+1  A: 

Usually C is compiled before running. This means that the source code is translated to executable machine instructions. So the source code is probably not available in memory when you run the program.

Thomas Padron-McCarthy
+1  A: 

Do you mean your program analyses machine code? Or C source?

Your C program, once it's compiled, is not in C anymore so the running program will be in machine code, not C.

Why don't you want to open the source file from disk?

Mark Pim
+1  A: 

I don't know if I have correctly understood the question, but I give it a try:

You can access to the pathname of the source file of your C software with the __FILE__ directive. Using it for purposes other than displaying it implies that it has not moved or disappeared since the last compilation.

mouviciel