@property method needs ()
Hi, in following example the @property method needs the () otherwise compiler error for row 24 is thrown. I cannot judge, whether the compiler behaves correct or not. Kind regards André --- alias fnError = void delegate(string s); interface IfSession { @property fnError addError(); } class Session: IfSession { private fnError _addError; @property fnError addError() { return _addError; } } void main() { auto session = new Session(); session._addError = delegate(s){}; session.addError()("test"); // Works session.addError("test"); // Does not work }
Re: How does this work?
On Sun, 23 Nov 2014 22:51:48 + Freddy via Digitalmars-d-learn wrote: > I know what this does, but can someone explain how it works? > > static if((typeof((inout int=0){ > > }))); > it was here somewhere. this is, as you can see, a lambda. `typeof()` can be used even for invalid code and will return special `error` type (don't try to catch it, just trust me ;-). in `static if` this `error` type means `false`. labmda that can not be compiled is obvious invalid, uncompilable code, so it has a type of `error`. and `inout` is a hack for some kind of functions/templates. to make a long story short: don't try to remember it all, you'll forget it next day. just take it as it is and be happy. ;-) signature.asc Description: PGP signature
Re: Casting in Safe D
On Sunday, 23 November 2014 at 19:37:45 UTC, Nordlöw wrote: I just noticed that void foo() @safe pure nothrow { void[] void_array = new void[3]; auto ubyte_array = cast(ubyte[])void_array; auto short_array = cast(short[])void_array; } compiles but gives a object.Error@(0): array cast misalignment because of the cast(short[]) I'm surprised---why is cast between different alignments and element lengths allowed at all in Safe D? As far as I understand, it's @safe because it's guaranteed to fail at run time on mismatches. Similarly, array accesses are @safe because invalid ones will throw RangeError: void foo(int[] a) @safe {a[100] = 13;} And even pointer dereferencing is @safe. Invalid ones will fail with a segfault at run time: void foo(int* a) @safe {*a = 13;}
How does this work?
I know what this does, but can someone explain how it works? static if((typeof((inout int=0){ })));
Casting in Safe D
I just noticed that void foo() @safe pure nothrow { void[] void_array = new void[3]; auto ubyte_array = cast(ubyte[])void_array; auto short_array = cast(short[])void_array; } compiles but gives a object.Error@(0): array cast misalignment because of the cast(short[]) I'm surprised---why is cast between different alignments and element lengths allowed at all in Safe D? IMO, cast(ubyte[]), should be safe here though.
Handmade Hero - Casey Muratori podcast about making a complete game in C from scratch.
Hi, I haven't seen this announced here so I'm stepping in for those that might find it to be of interest... should be everyone if you ask me. Casey Muratori started, like one week ago into serious stuff, a daily podcast where he codes a complete, professional-quality game live and explains every single line of it. He uses the C programming language and plan to not use any external library at all! Casey's solid experience, sound work ethic and "no bullshit" approach is a "refreshing gold mine". Here we go: http://handmadehero.org/
Re: undefined reference to class template
On Friday, 14 November 2014 at 23:29:34 UTC, Satoshi wrote: Hi, Im using GDC 4.9.0 compiler. I have template classes like "public class LinkedList(T) {...}" and when I try compile it together, everything works fine. But when I compile every source file to separate object file and link it together with ld Ill get errors like: "/os/KernelLand/Kernel/TaskManager/Thread.d:99: undefined reference to `_D7Library10LinkedList45__T10LinkedListTC11TaskManager6Thread6ThreadZ10LinkedList6__ctorMFNaNbNfZC7Library10LinkedList45__T10LinkedListTC11TaskManager6Thread6ThreadZ10LinkedList'" Im compiling it with command like: gdc -mcmodel=kernel -nostdlib -mno-red-zone -Wall -masm=intel -frelease -finline-functions -O3 -o obj-x86_64/abc.d.o -c abc.d Here is full error log http://pastebin.com/SjnYjqKh makefile https://github.com/Bloodmanovski/Trinix/blob/dc80f3197f59fe96e9f4e29cea670ff2c7eaa342/KernelLand/Kernel/Makefile#L104 LinkedList class https://github.com/Bloodmanovski/Trinix/blob/dc80f3197f59fe96e9f4e29cea670ff2c7eaa342/KernelLand/Kernel/Library/LinkedList.d Can anyone help me how to solve this problem? Thanks (Sorry for bad english) Sounds like you're not passing in LinkedList.d while compiling a file that uses it. You need to include all used files, including imports, on the command line when compiling. The undefined reference indicates it can't find the source code or di file containing LinkedList. Tools like rdmd do this for you by looking at the imports used automatically. If not that, I'm not sure if this will help, but try using -femit-templates (similar to -allinst in DMD I believe?). Besides that, all I can really suggest is double checking that you're actually including the object file containing LinkedList when you're linking and the source file when compiling.