compiler uses only used functions ?

Just starting out? Need help? Post your questions and find answers here.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

compiler uses only used functions ?

Post by MyTrial »

Hi

I have a dummie question: Is the compiler optimised that not used functions are not in the compiled program?

Why I ask: I made some sub source files with global handling functions and bind them in my program source with XIncludeFile. When I make a program with much of all functions the compiled file size is nearly same as a program with only one function of that used (PB3.94).

Or should I use an other way to do that?
But I do not want DLLs or separate files to handle.

Many thanks for your help.
SKER
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

No, the PB4 changelog says, that procedures who are used will be compiled.

I asked this a long time ago, and I made a test:

Code: Select all

Procedure AND51()

; Code, and what eveer you want

EndProcedure
Write this without calling the procedure and you see: the EXE is bigger than a EXE without any code :shock:
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

Nope. Non used functions are not included. But if u use strings they are.
Just try it.

Code: Select all

procedure Test()
Me.l='tseT'
endprocedure
Do u find any "Test" in the exe?
Apart from that Mrs Lincoln, how was the show?
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

This compiler feature is very restricted (reason: I think the speed of the
compiler).

Code: Select all

procedure test()
  a+4
  procedurereturn a
endprocedure
won't be included, but

Code: Select all

procedure test1()
  a+4
  if a = 5
    test2()
  endif
  procedurereturn a
endprocedure
procedure test2()
  test1()
endprocedure
there both procedures will be included. The feature only works if there is
NO (not a single) reference to the procedure in the code, even if this
reference is in another not used procedure, the procedure will be included.


So: Mostly, from a bit more complex function libraries most of the functions
will be included.
Athlon64 3700+, 1024MB Ram, Radeon X1600
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Another possibility is to use a user library instead of an include.

AFAIK, only used userlib functions are included.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply