One very basic question

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

One very basic question

Post by SkyManager »

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 :?:
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

If I remember correctly PureBasic 4 only included the functions you used.
I like logic, hence I dislike humans but love computers.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Edit the include file to contain only the three functions you want, save it with a different name, 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

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()
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

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.
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

> I think it will include all functions from an include file regardless.
It's like I described in my post above. If include files are handled differently than the main file, then there's a problem somewhere.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Why don't you just have a look at the generated assembly code to confirm that what I said is correct?
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Yes, I can. But I suppose there will be an official answer from PB support. At least, you folks have already encountered this problem before.

Anyway, thank you all for the help.
hagibaba
Enthusiast
Enthusiast
Posts: 170
Joined: Fri Mar 05, 2004 2:55 am
Location: UK
Contact:

Post by hagibaba »

what Trond said is correct.

If you don't call a procedure in your PB source code it won't be compiled to the executable (PB v4.02). It also makes no difference if the procedure is in an include file or not.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> 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.
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 »

Trond wrote:Why don't you just have a look at the generated assembly code to confirm that what I said is correct?
My apology Trond.

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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> 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.

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.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Actually, I have done some similar tests with similar results as yours.
Thank you for the help.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

I'm wrong again. :cry: :oops:
Post Reply