digitalmars.D.learn - Type properties
- ric maicle (13/13) Jan 06 2016 Why is init allowed to be redefined but not sizeof?
- ric maicle (3/16) Jan 06 2016 Found this
- Steven Schveighoffer (9/22) Jan 07 2016 At the moment, we need this. The TypeInfo member that contains the
- Jacob Carlborg (15/18) Jan 07 2016 NSObject init_() @selector("init");
Why is init allowed to be redefined but not sizeof? dmd 2.069 import std.stdio; struct Foo { static int init = 5; static int sizeof = 0; } void main() { writeln(Foo.init); writeln(Foo.sizeof); } Error: variable integer.Foo.sizeof .sizeof property cannot be redefined
Jan 06 2016
On Wednesday, 06 January, 2016 04:01 PM, ric maicle wrote:Why is init allowed to be redefined but not sizeof? dmd 2.069 import std.stdio; struct Foo { static int init = 5; static int sizeof = 0; } void main() { writeln(Foo.init); writeln(Foo.sizeof); } Error: variable integer.Foo.sizeof .sizeof property cannot be redefinedFound this https://issues.dlang.org/show_bug.cgi?id=7066
Jan 06 2016
On 1/6/16 3:01 AM, ric maicle wrote:Why is init allowed to be redefined but not sizeof? dmd 2.069 import std.stdio; struct Foo { static int init = 5; static int sizeof = 0; } void main() { writeln(Foo.init); writeln(Foo.sizeof); } Error: variable integer.Foo.sizeof .sizeof property cannot be redefinedAt the moment, we need this. The TypeInfo member that contains the initialization data was called init. It was very recently switched to initializer, but we cannot get rid of that alias for a few releases. After that, I think we can consider removing that ability from the language. One thing that just occurred to me though, Objective-C makes use of the init function quite a bit. I wonder how getting rid of init as a customizable member would affect that. -Steve
Jan 07 2016
On 2016-01-07 15:30, Steven Schveighoffer wrote:One thing that just occurred to me though, Objective-C makes use of the init function quite a bit. I wonder how getting rid of init as a customizable member would affect that.NSObject init_() selector("init"); With the full support for Objective-C, binding the "init" method would not be necessary at all. This will be supported: auto foo = new NSObject; Which will be lowered to: auto foo = NSObject.alloc.init; It will also be possible to bind a D constructor to an init method: extern (Objective-C) class Foo : NSObject { this(Foo) selector("initWithFoo:"); } Although, it's still a breaking change, which affect other projects. -- /Jacob Carlborg
Jan 07 2016