Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Sven Barth
Am 31.03.2016 17:28 schrieb "Graeme Geldenhuys" < mailingli...@geldenhuys.co.uk>: > > On 2016-03-31 16:06, Michael Van Canneyt wrote: > > > I am guessing it comes from C++/Java/C#, which AFAIK do not have > > the 'initialization' section. But that's just a guess. > > [my personal opinion - feel fre

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Michael Van Canneyt
On Thu, 31 Mar 2016, Maciej Izak wrote: 2016-03-31 17:06 GMT+02:00 Michael Van Canneyt : I imagine so, yes. It is one of the reasons why I don't really see the usefulness of this construct, except that it looks OOP-ish. It is mostly for initialization "class var" related stuff inside rec

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Graeme Geldenhuys
On 2016-03-31 16:46, Dmitry Boyarintsev wrote: > One could use an alternative approach and have "binding" units. > The unit would consist of initialization section only, that does the > necessary binding code. tiOPF's TestSuite project has a tiTestDependencies.pas unit which primarily consists of

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Michael Van Canneyt
On Thu, 31 Mar 2016, Dmitry Boyarintsev wrote: On Thu, Mar 31, 2016 at 11:28 AM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: On 2016-03-31 16:06, Michael Van Canneyt wrote: I usually have a 'Start Application' kind of routine where I register all the necessary things, link thi

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Maciej Izak
2016-03-31 17:06 GMT+02:00 Michael Van Canneyt : > I imagine so, yes. > > It is one of the reasons why I don't really see the usefulness of this > construct, except that it looks OOP-ish. > > It is mostly for initialization "class var" related stuff inside records and classes. Very usefully especi

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Dmitry Boyarintsev
On Thu, Mar 31, 2016 at 11:28 AM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: > On 2016-03-31 16:06, Michael Van Canneyt wrote: > > I usually have a 'Start Application' kind of routine where I register all > > the necessary things, link things together (needed if you follow 'loosely

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Vojtěch Čihák
I meant Delphi optimization but I'm mistaking since they have it documented.   B. __ Od: silvioprog Komu: "FPC-Pascal users discussions" Datum: 31.03.2016 16:17 Předmět: Re: [fpc-pascal] Class constructor called uncon

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Graeme Geldenhuys
On 2016-03-31 16:06, Michael Van Canneyt wrote: > I am guessing it comes from C++/Java/C#, which AFAIK do not have > the 'initialization' section. But that's just a guess. [my personal opinion - feel free to ignore this paragraph] I hate such "features" pulled in from other languages, when Objec

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Michael Van Canneyt
On Thu, 31 Mar 2016, silvioprog wrote: On Thu, Mar 31, 2016 at 11:28 AM, Michael Van Canneyt < mich...@freepascal.org> wrote: [...] I suspect the problem is not in the mode, but in detecting whether a class is used or not in a program. It becomes very complicated when you use e.g. run-time p

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 11:28 AM, Michael Van Canneyt < mich...@freepascal.org> wrote: [...] > I suspect the problem is not in the mode, but in detecting whether a class > is used > or not in a program. It becomes very complicated when you use e.g. > run-time packages. > Hm... so FPC class constr

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Michael Van Canneyt
On Thu, 31 Mar 2016, silvioprog wrote: On Thu, Mar 31, 2016 at 10:58 AM, Vojtěch Čihák wrote: IMO compilers should be dogmatic otherwise one cannot rely on them. This looks to me like advocating wrong optimization. Blaazen Thanks for reply Vojtěch, but are you referring to Delphi or F

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 10:58 AM, Vojtěch Čihák wrote: > IMO compilers should be dogmatic otherwise one cannot rely on them. This > looks to me like advocating wrong optimization. > > > > Blaazen > Thanks for reply Vojtěch, but are you referring to Delphi or FPC optimization? I think that FPC s

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Vojtěch Čihák
fpc-pascal] Class constructor called unconditionally  As long as you don't use the class anywhere outside the class itself, the compiler takes this as the class not used at all and hence won't call the class constructor. So I guess you have to use the intialization section instead of tweak

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 10:49 AM, Sven Barth wrote: > Am 31.03.2016 15:33 schrieb "silvioprog" : > > After read this explanations, is there some compiler option to make FPC > with this same Delphi behaviour? I'm using MODE DELPHI. > > No, there is not. Currently class constructors (and destructor

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread Sven Barth
Am 31.03.2016 15:33 schrieb "silvioprog" : > After read this explanations, is there some compiler option to make FPC with this same Delphi behaviour? I'm using MODE DELPHI. No, there is not. Currently class constructors (and destructors) are called always. Regards, Sven __

[fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
Hello, First, take a look at this small project: === code === program Project1; {$IFDEF FPC} {$MODE DELPHI} {$ENDIF} {$IFDEF MSWINDOWS} {$APPTYPE CONSOLE} {$ENDIF} type TFoo = class public class constructor Create; end; class constructor TFoo.Create; begin Writeln('TFoo.