Lite-C Multiple c Files possible?

Posted By: Dark_samurai

Lite-C Multiple c Files possible? - 01/18/14 11:27

Dear all,

has some of you got Lite-C to compile multiple *.c files like a normal c compiler does? When I remember correctly, this was only possible by including *.c files (with #include "unit1.c"), which is really not a good programming style.

If I for example do this:


The prototype of PrintMsg() is defined in unit1.h. PrintMsg() is implemented in unit1.c:

Code:
#include <acknex.h>

function PrintMsg(STRING* msg)
{
	error(msg);
}



This is the very straight forward way how information hiding using multiple *.c files is implemented in standard C. But in Lite-C this leads to a "Empty function called in main" error during runtime. Has anybody got this running, or are multiple *.c files simply not suported by the compiler/linker?

Thanks for clarification!
Posted By: WretchedSid

Re: Lite-C Multiple c Files possible? - 01/18/14 12:29

Nope, Lite-C is still just one translation unit.
Posted By: Superku

Re: Lite-C Multiple c Files possible? - 01/18/14 12:50

What I normally do is I write #include "unit1.c" at the bottom of the *.h file which allows me to only include the *.h file in my main program and use that file for reference. I know that's not exactly what you are looking for but I think it's better than just using *.c files.
Posted By: Dark_samurai

Re: Lite-C Multiple c Files possible? - 01/18/14 12:57

Thanks for your answers wink

@Superku: I also worked with such workarounds, but basicly I miss the information hiding principle of seperate translation units. Maybe JCL is willing to implement that in one of the next updates...
Posted By: sivan

Re: Lite-C Multiple c Files possible? - 01/18/14 14:26

hehh, I just had a shitty Friday because of a wrong script restructurization into .h and .c files... I included first the .h files than the .c files in a main header file that is used by both the editor and the game, no errors, my editor works fine, but some complex rts map decomposition and pathfinding stuff do not want to work again as before... maybe only the .c files should be included in that main file, and the .c files should include the .h files used by it? (header guard or whatever its name is used, you know those ifndef define endif thingie)

Edit: my includes have been fine, I just commented out something that would had been necessary... backups are the best friends.
Posted By: WretchedSid

Re: Lite-C Multiple c Files possible? - 01/18/14 15:41

include guards.

Anyhow, I doubt that multiple translation units will make it into Lite-C. Not so much because of the compiler, but because of the mostly non-existent linker.
Why do I think there is no linker? Because Dark_Samurai's code would've never gotten through a linker ever.
Posted By: Dark_samurai

Re: Lite-C Multiple c Files possible? - 01/18/14 22:41

Quote:
Not so much because of the compiler, but because of the mostly non-existent linker.


Yes this could indeed be the case...

Quote:
Because Dark_Samurai's code would've never gotten through a linker ever.


Why?

Edit: I guess you ment that the linker has no address for the function because the second *.c file is not compiled (because of the missing feature to compile multiple translation units)? So normally you should get the error during linking, not during runtime...
© 2024 lite-C Forums