fbc removes unused private procedures/variables?

General FreeBASIC programming questions.
Post Reply
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

fbc removes unused private procedures/variables?

Post by Imortis »

See quote from dkl here: .viewtopic.php?t=23405
And beginning of discussion from here: .viewtopic.php?f=3&t=25230#p226853

I have not tested to see if private functions and var not used in the main bas vs. included in a file operate any differently, but I would assume not because as dodicat stated:
dodicat wrote:#include "somefile" is a shortcut to copy and paste in Freebasic.
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: fbc removes unused private procedures/variables?

Post by fxm »

Imortis wrote:I have not tested to see if private functions and var not used in the main bas vs. included in a file operate any differently, but I would assume not because as dodicat stated:
dodicat wrote:#include "somefile" is a shortcut to copy and paste in Freebasic.
I checked this for private procedures.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: fbc removes unused private procedures/variables?

Post by Josep Roca »

It doesn't matter if the extension is .bas, .inc, .txt or wathever, or if you use one file or a dozen. The keys are that they must contain source code and that the procedures and/or methods will be prefixed as private. This technique can't be used with DLLs or libraries, only with source code.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: fbc removes unused private procedures/variables?

Post by Imortis »

As I have never used private in this manner (only used the access modifier for UDTs/Classes), I was not sure what it did here. It's whole purpose is to mark a procedure as internally linked. This is why the compiler is able to say for sure it is not needed. If nothing in the main program uses it, it is not used at all.

Interesting.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: fbc removes unused private procedures/variables?

Post by dodicat »

If we are talking include files, then private functions are in the same program as running code, and thus accessible.

If the private functions are in a .bas file and compiled with -lib then the functions are not accessible by loading the library and using function declarations in the normal way, or any other way as far as I can see.

For creating a .dll file of private functions, the compiler won't allow the keyword export at a private function, so a .dll of private functions will not compile.

These are the three options I have tried out anyway.
Also
A private member sub of a udt in the static library can be accessed as though the word private was not used.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: fbc removes unused private procedures/variables?

Post by Josep Roca »

The way I use this feature is the same that I used with PowerBASIC. I have built a framework with many classes and wrapper procedures using include files, declaring all the procedures and methods as private. When I need the functionality provided by some of the include files, I simply use #include "xxx.inc". The main advantages of using this technique is dead code removal, conditional compilation when needed and much less work to maintain the code.
Post Reply