If I create an application which include this file but use only 3 functions, will the resulting exe include 30 functions or only 3 functions
One very basic question
-
SkyManager
- Enthusiast

- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
One very basic question
I have an include file which contains about 30 functions.
If I create an application which include this file but use only 3 functions, will the resulting exe include 30 functions or only 3 functions
If I create an application which include this file but use only 3 functions, will the resulting exe include 30 functions or only 3 functions
- Joakim Christiansen
- Addict

- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
It will include all called functions, including those which are called from uncalled functions:
Code: Select all
procedure Included()
endprocedure
procedure NotIncluded()
Included()
endprocedure
procedure Included2()
endprocedure
Included2()
I think it will include all functions from an include file regardless.
With a compiled Purebasic user library, on the other hand, because the library is split (and basically has 1 object file per function), only the functions which are called get thrown into the final executable.
With a compiled Purebasic user library, on the other hand, because the library is split (and basically has 1 object file per function), only the functions which are called get thrown into the final executable.
I may look like a mule, but I'm not a complete ass.
Include files are handled exactly the same as the main source file in that all functions are placed into the exe regardless. As far as my understanding goes, only compiled PB user libraries offer the flexibility of being able to only include functions which are referenced (even if they're not actually used I guess).
I may look like a mule, but I'm not a complete ass.
-
SkyManager
- Enthusiast

- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
> If you don't call a procedure in your PB source code it won't be compiled
Not entirely true. Compile an exe with an uncalled procedure that has a string
in it, then search that exe with a hex editor for that string, and you'll find it.
Fred explained that strings are still included, but generally the procedures aren't.
I can't find his full explanation now, despite searching here for about 20 minutes.
Not entirely true. Compile an exe with an uncalled procedure that has a string
in it, then search that exe with a hex editor for that string, and you'll find it.
Fred explained that strings are still included, but generally the procedures aren't.
I can't find his full explanation now, despite searching here for about 20 minutes.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
My apology Trond.Trond wrote:Why don't you just have a look at the generated assembly code to confirm that what I said is correct?
Everytime I looked at the generated assembly I saw the procedure code translated into asm even when it wasn't called. What I missed was the fact that it was embedded within a macro and the macro only utilised if the procedure was actually called. That's a nice way of doing it.
I may look like a mule, but I'm not a complete ass.
> compile two programs, one using the old include and one
> using the new include and then compare the size of the files.
> This should show you conclusively what PB does.
Not so. I just compiled the following two sources, and both create executables
of exactly 2.00 KB (2,048 bytes). This is due to Win32 executable sizes being
on a boundary of some kind -- I'm not very technical for the correct phrase.
Anyway, here's the conclusive proof: compile these two sources, then load each
in a hex editor. You'll see BOTH contain the DeleteFileA API in them, even though
the second one DOESN'T call the procedure that contains the DeleteFile command.
> using the new include and then compare the size of the files.
> This should show you conclusively what PB does.
Not so. I just compiled the following two sources, and both create executables
of exactly 2.00 KB (2,048 bytes). This is due to Win32 executable sizes being
on a boundary of some kind -- I'm not very technical for the correct phrase.
Anyway, here's the conclusive proof: compile these two sources, then load each
in a hex editor. You'll see BOTH contain the DeleteFileA API in them, even though
the second one DOESN'T call the procedure that contains the DeleteFile command.
Code: Select all
; This one DOES call the procedure.
Procedure zzz(file$)
DeleteFile_(file$)
EndProcedure
Sleep_(1)
zzz("c:\nosuchfile")
Code: Select all
; This one DOESN'T call the procedure,
; but the exe still has DeleteFileA!
Procedure zzz(file$)
DeleteFile_(file$)
EndProcedure
Sleep_(1)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
SkyManager
- Enthusiast

- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong

