• Welcome to PlanetSquires Forums.
 

inc files?

Started by Upsydaisy, January 12, 2023, 11:26:49 AM

Previous topic - Next topic

Upsydaisy

Hi,

I noticed in the WinFBE source that you have inc files and a corresponding bi header. Why do you do this and not use the bas extension? I'm guessing it is done to signify that source file goes along with its bi header as it could be confused as being a main file?

Paul Squires

I use *.inc files because that is the extension that we used in the old PowerBASIC days before I moved to FreeBASIC.

I program by "including" my *.inc files into my main .BAS file. Computers are so fast these days that there is rarely a huge benefit to compiling the separate files into object files and then linking them all afterwards (like traditional C/C++ programs).

You can still do the C/C++ approach by specifying the file to be a "module" within WinFBE at which point WinFBE will only recompile the module if the source has changed. However, I find that it is easier to use the #include approach especially if I have a lot of interconnected code that is shared throughout the application.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Upsydaisy

Thanks Paul for that.

I noticed in the categories in WinFBE is the module type. If it is set to that is it doing the c/c++ style of compiling where it is compiling the source file to an obj then linking it with the main program? Doing it this way we would #include once "MyModule.bi" from the main source file?

So for your style you would set the category of the *.inc file to normal and then just #include once "MyModule.inc" from the main file. It could though just be a *.bas file, you only do it as you came from PowerBASIC.

Doing it this way I guess it builds the program in one go without having to link it together with the other modules?

José Roca

I have used the .inc extension for include files since DOS times, long before Microsoft decided to use .bi [that means Basic include]. Many FB users use both .bi for headers and include files, and .bas for the main program and for modules. We use .bi for headers and .inc for include files. Other languages, such assembler or Pascal, also use .inc (or should they have used .pi, for Pascal include?).

My WinFBX framework does not use modules, only include files, because it is the easy way with FB to get dead code removal (prefixing the procedure names with the keyword PRIVATE). If you use modules, all the code in a module is added to your executable, instead of only the procedures being called.

Paul Squires

Quote from: Upsydaisy on January 12, 2023, 11:55:16 AMI noticed in the categories in WinFBE is the module type. If it is set to that is it doing the c/c++ style of compiling where it is compiling the source file to an obj then linking it with the main program?
The compiled *.o object files get stored in the ".wfbe" subfolder located off of your project.

QuoteDoing it this way we would #include once "MyModule.bi" from the main source file?
Yes, that is correct.

QuoteSo for your style you would set the category of the *.inc file to normal and then just #include once "MyModule.inc" from the main file. It could though just be a *.bas file, you only do it as you came from PowerBASIC.
Yes, you are 100% correct. You could name the file whatever you want (inc, bas, etc.) but you need to place it in the "Normal" branch and then #Include it into your main BAS file.

QuoteDoing it this way I guess it builds the program in one go without having to link it together with the other modules?
Exactly. Unless you have a very, very, old computer, you will not see much of a difference in compile time.

José makes a great point about the dead code removal. You can see it with his extensive set of WinFBX library code (which every WinFBE should be using extensively!). You include his full INC file but only the actual code that you use from that include will actually be included in your final EXE. If that include had been compiled to an object file and then linked to the exe then the entire file (not just the used functions) will be included the final exe.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer