Do orphan procedures get compiled?

Everything else that doesn't fall into one of the other PB categories.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Do orphan procedures get compiled?

Post by Seymour Clufley »

If a procedure is not linked (directly or via a chain of procedures) to the main program code, does it get included in the compiled exe or is it left out, to reduce filesize?

What about structures that are never used, etc.?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I'm not sure if it is solved meanwhile...

in earlier versions, procedures that were never called were left out,
Procedures that were called from Procedures were implemented,
even if the calling Procedure was never called.

there are plugins/preparser to deal with that, I think...


Structures are not at all implemented in the exe in a form that needs memory,
they are only a construct to describe complex offset combinations in a way readable for Humans.
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

They do get compiled under 4.20, I think...

Creating an executable with 4.20 and this:

Code: Select all

; IncludeFile "c:\software\purebasic\_projects\x_lib\x_lib.pb"
a = 1
Debug "Ok"
... resulted in a file of 3.584 bytes.

Using this:

Code: Select all

IncludeFile "c:\software\purebasic\_projects\x_lib\x_lib.pb"
a = 1
Debug "Ok"
... resulted in an executable of 68096 bytes.

4.30's exe was about 600 bytes larger.

(Still not bad realizing that x_lib is about 5000 lines. And before someone asks: everything in that file x_lib is enclosed in procedures so should not add to exe size unless procedures are included.)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Generally speaking procedures which are not referenced at all will not be included in the final exe.

Consider the following :

Code: Select all

Procedure test1()
  a+1
EndProcedure

Procedure test2()
  a+1
EndProcedure

a + 5
In this case neither function will be included in the final exe because neither is referenced anywhere in the code.

However, in the following code :

Code: Select all

Procedure test1()
  a+1
EndProcedure

Procedure test2()
  a+1
  test1()
EndProcedure

a + 5
the procedure test1() will be included in the final exe even though it is only referenced within test2() which itself will not be included in the final exe.

:)
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@srod: The following example has DeleteFileA and MessageBoxA in the final
exe, but I don't know whether the procedure code is included or just the API
headers:

Code: Select all

Procedure test1()
  DeleteFile(a$)
EndProcedure

Procedure test2()
  MessageRequester("","")
EndProcedure

a + 5
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Just the stubs (taken from the relevant import libraries) are included. This is because PB's generated ASM is declaring the appropriate external symbols.
I may look like a mule, but I'm not a complete ass.
Post Reply