Programming Newbie Compiler Question
Re: Programming Newbie Compiler Question
@caseih,
precisely what I've been referring to: PowerBASIC DOS (ver. 2.1x) ... (I've never used QB).
precisely what I've been referring to: PowerBASIC DOS (ver. 2.1x) ... (I've never used QB).
Re: Programming Newbie Compiler Question
It occurs to me that with FB you really don't need a build system to use separate .bas files. Just passing all the .bas files to FBC at once is sufficient. In fact for some big projects, "fbc -o my.exe *.bas" does the trick. Alternatively, "fbc -o my.exe *.o" if one wants to compile individual files. So there's no reason to continue including whole .bas files with FreeBasic, and should be strongly discouraged, even when not using a build system. Worst case, compiling *.bas is no slower than including the .bas files (nor faster), but is more future-proof if a person moves to an IDE with a build system in the future.
Re: Programming Newbie Compiler Question
Well, as strongly as you seem to be in favour of build systems, by cons, there are reasons
to avoid them, too.
e.g. FBEdit Project:
- using a: not yet written or completed library, from "main.bas" [is a massive PITA] ...
versus, including the source of the: "to be library" (separate compile tests possible).
to avoid them, too.
e.g. FBEdit Project:
- using a: not yet written or completed library, from "main.bas" [is a massive PITA] ...
versus, including the source of the: "to be library" (separate compile tests possible).
Re: Programming Newbie Compiler Question
In my last post, I mentioned using separate .bas files without a build system, and without resorting to including them.
Re: Programming Newbie Compiler Question
Now, this is what I'd call: strange/highly unusual ...caseih wrote:... without resorting to including them.
As I'm keeping all sources in one Directory/Folder, your preferred option = impossible!
I don't understand your reasoning (since, it makes no sense) against including another
.bas file.
(I also don't particularly, like build systems, as you might have guessed by now! To me,
they tend to just add another layer of obfuscation, to the build process itself.)
To me it's the same as including a .bi, which then may be loading a lib (just a compiled
source) or the source itself. I'd call that: same difference!
Re: Programming Newbie Compiler Question
To each his own! I probably don't go as far back as you do, but I've never seen include used that way (where include means literally include the file's content) in any language besides BASIC here, and maybe PHP (interpreted language, however). It's definitely strange and highly unusual in C, and almost all other compiled languages I can think of that require a linking step.
Re: Programming Newbie Compiler Question
FreePascal, Delphi and Turbo Pascal can do it (has a typical extension for such cases even; .INC, which can be headers or code). However the modular unit system is far more widely used.caseih wrote:To each his own! I probably don't go as far back as you do, but I've never seen include used that way (where include means literally include the file's content) in any language besides BASIC here, and maybe PHP (interpreted language, however). It's definitely strange and highly unusual in C, and almost all other compiled languages I can think of that require a linking step.
FPC/Lazarus uses it more than Delphi/TP, mostly because its multi platform and widgetset concepts. It is mostly used in the deeper parts of the RTS, and the Lazarus LCL (to build with varying backend widgetsets, the widgetspecific units include common parts). It is also used to break up very large units by topic. (easier with SVN)
Last edited by marcov on Mar 02, 2018 17:09, edited 1 time in total.
Re: Programming Newbie Compiler Question
Thanks marcov,
that reminds me: .INC was also used in PowerBASIC, ask: José Roca / Paul Squires ...
(they're using it extensively, even in FB -- WinFBE (IDE) also supports it).
(and, probably other late PowerBASIC users, that migrated to FB ...)
that reminds me: .INC was also used in PowerBASIC, ask: José Roca / Paul Squires ...
(they're using it extensively, even in FB -- WinFBE (IDE) also supports it).
(and, probably other late PowerBASIC users, that migrated to FB ...)
Re: Programming Newbie Compiler Question
Exactly. In languages like C and FB, the .bi file forms the interface of a modular unit and is used in a similar way to Pascal's units (has the same effect). FP's unit's appear to consist of a single file, unlike a C-like language, which works well given the strict separation of interface and implementation in Pascal. I'm not not sure how one interfaces with dlls... are there interface-only files in FP? I'd check the GTK bindings to see, but apparently Sourceforge is down right now.marcov wrote:However the modular unit system is far more widely used.
Anyway, like I said, to each his own. I will admit there are use cases, but from experience on the list in recent days, one has to be very careful when doing it.
-
- Posts: 564
- Joined: Sep 27, 2016 18:20
- Location: Valencia, Spain
Re: Programming Newbie Compiler Question
We are using include files instead of libraries or modules mainly because it is the only way to have dead code removal with FreeBasic. See: viewtopic.php?t=25237MrSwiss wrote:Thanks marcov,
that reminds me: .INC was also used in PowerBASIC, ask: José Roca / Paul Squires ...
(they're using it extensively, even in FB -- WinFBE (IDE) also supports it).
(and, probably other late PowerBASIC users, that migrated to FB ...)
-
- Posts: 4308
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Programming Newbie Compiler Question
I remember the conversation you provided a link to.JosepRoca wrote:We are using include files instead of libraries or modules mainly because it is the only way to have dead code removal with FreeBasic.
Regards the quote above.: Can you prove that?
I tried all sorts of combinations at the time of the conversation but could not prove it. It seemed to me that your explanation was just a weeny bit short of a full explanation and it was that weeny bit short that stopped me from proving it.
Some working code to prove that an exe size does change with your method may persuade folk to use it because I reckon that nobody is.
-
- Posts: 564
- Joined: Sep 27, 2016 18:20
- Location: Valencia, Spain
Re: Programming Newbie Compiler Question
Take for example this code and compile it with the -rr option to generate the intermediate asm file:
The asm file will contain:
That is, code for the three SUBs is generated, although we are only calling Foo1.
Now add PRIVATE to the subs:
And the output is:
And you can see that only code for Foo1 has been generated.
If you use my WinFBX framework, you will notice that it does not generate very big files even though it contains lots of classes and many hundreds of procedures.
Code: Select all
'#CONSOLE ON
SUB Foo1 (BYVAL x AS LONG)
? x
END SUB
SUB Foo2 (BYVAL x AS LONG)
? x
END SUB
SUB Foo3 (BYVAL x AS LONG)
? x
END SUB
Foo1 123
PRINT
PRINT "Press any key..."
SLEEP
Code: Select all
.intel_syntax noprefix
.section .text
.balign 16
.globl _FOO1@4
_FOO1@4:
push ebp
mov ebp, esp
.Lt_0004:
push 1
push dword ptr [ebp+8]
push 0
call _fb_PrintInt@12
.Lt_0005:
mov esp, ebp
pop ebp
ret 4
.balign 16
.globl _FOO2@4
_FOO2@4:
push ebp
mov ebp, esp
.Lt_0006:
push 1
push dword ptr [ebp+8]
push 0
call _fb_PrintInt@12
.Lt_0007:
mov esp, ebp
pop ebp
ret 4
.balign 16
.globl _FOO3@4
_FOO3@4:
push ebp
mov ebp, esp
.Lt_0008:
push 1
push dword ptr [ebp+8]
push 0
call _fb_PrintInt@12
.Lt_0009:
mov esp, ebp
pop ebp
ret 4
.balign 16
_fb_ctor__1:
.Lt_0002:
push 123
call _FOO1@4
push 1
push 0
call _fb_PrintVoid@8
push 1
push 16
push offset _Lt_000A
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
push -1
call _fb_Sleep@4
.Lt_0003:
ret
.section .data
.balign 4
_Lt_000A: .ascii "Press any key...\0"
.section .ctors
.int _fb_ctor__1
Now add PRIVATE to the subs:
Code: Select all
'#CONSOLE ON
PRIVATE SUB Foo1 (BYVAL x AS LONG)
? x
END SUB
PRIVATE SUB Foo2 (BYVAL x AS LONG)
? x
END SUB
PRIVATE SUB Foo3 (BYVAL x AS LONG)
? x
END SUB
Foo1 123
PRINT
PRINT "Press any key..."
SLEEP
Code: Select all
.intel_syntax noprefix
.section .text
.balign 16
_fb_ctor__1:
.Lt_0002:
push 123
call _FOO1@4
push 1
push 0
call _fb_PrintVoid@8
push 1
push 16
push offset _Lt_000A
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
push -1
call _fb_Sleep@4
.Lt_0003:
ret
.balign 16
_FOO1@4:
push ebp
mov ebp, esp
.Lt_0004:
push 1
push dword ptr [ebp+8]
push 0
call _fb_PrintInt@12
.Lt_0005:
mov esp, ebp
pop ebp
ret 4
.section .data
.balign 4
_Lt_000A: .ascii "Press any key...\0"
.section .ctors
.int _fb_ctor__1
If you use my WinFBX framework, you will notice that it does not generate very big files even though it contains lots of classes and many hundreds of procedures.
-
- Posts: 4308
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Programming Newbie Compiler Question
Well, it certainly looks that way.JosepRoca wrote:And you can see that only code for Foo1 has been generated.
However, when I compile to exe I get 32,256 bytes for private and 32,256 bytes for not private. OK, the Subs are small but I would have expected some difference. Maybe not - maybe we need some larger Subs to see a difference in exe sizes.
-
- Posts: 564
- Joined: Sep 27, 2016 18:20
- Location: Valencia, Spain
Re: Programming Newbie Compiler Question
Well, the size of the exe on disk depends also of the cluster size. Although with this small test the size on disk is the same, the second will have more unused space in the cluster. But if instead of three tiny subs you include a file with many procedures, the difference in size will be very noticeable.
Re: Programming Newbie Compiler Question
Using the assembler backend? Maybe FB doesn't emit section data, or you must instruct it to do so?Josep Roca wrote: We are using include files instead of libraries or modules mainly because it is the only way to have dead code removal with FreeBasic. See: viewtopic.php?t=25237
Does section based smartlinking work on Windows at all with LD? (FPC dropped LD as default over 10 years ago, so I don't know the current situation)