Re: readonly?

2012-07-10 Thread David Nadlinger
On Wednesday, 11 July 2012 at 06:34:29 UTC, Tobias Pankrath wrote: This escapes a stack reference. Ins't b supposed to be allocated on the heap? The Bar instance is, but the pointer to it is not. Making _b a Rebindable instead of using a pointer (to what effectively is a pointer to the real

Re: readonly?

2012-07-10 Thread Jonathan M Davis
On Wednesday, July 11, 2012 08:34:28 Tobias Pankrath wrote: > > This escapes a stack reference. > > Ins't b supposed to be allocated on the heap? The object is. The reference is not. &b is taking the address of the reference, not the object. - Jonathan M Davis

Re: readonly?

2012-07-10 Thread Tobias Pankrath
This escapes a stack reference. Ins't b supposed to be allocated on the heap?

Re: Compilation failure

2012-07-10 Thread Timon Gehr
On 07/11/2012 04:25 AM, ixid wrote: in some way it sees global immutables almost as enums This seems like a bad idea. Consistency of behaviour would seem to be a good principle to expect of a language. You are right; this is a bug.

Re: Compilation failure

2012-07-10 Thread ixid
in some way it sees global immutables almost as enums This seems like a bad idea. Consistency of behaviour would seem to be a good principle to expect of a language.

Re: readonly?

2012-07-10 Thread Timon Gehr
On 07/11/2012 12:58 AM, Ali Çehreli wrote: On 07/10/2012 03:53 PM, Namespace wrote: const(T)* ? Example? class Bar {} class Foo { const(Bar) * _b; void SetBar(const(Bar) * b) { _b = b; } } void main() { auto b = new Bar(); auto f = new Foo(); f.SetBa

Re: readonly?

2012-07-10 Thread Namespace
class Bar {} class Foo { const(Bar) * _b; void SetBar(const(Bar) * b) { _b = b; } } void main() { auto b = new Bar(); auto f = new Foo(); f.SetBar(&b); } Ali Hmm... That's good. Thanks.

Re: readonly?

2012-07-10 Thread Ali Çehreli
On 07/10/2012 03:53 PM, Namespace wrote: const(T)* ? Example? class Bar {} class Foo { const(Bar) * _b; void SetBar(const(Bar) * b) { _b = b; } } void main() { auto b = new Bar(); auto f = new Foo(); f.SetBar(&b); } Ali

Re: readonly?

2012-07-10 Thread Namespace
const(T)* ? Example?

Re: readonly?

2012-07-10 Thread Tobias Pankrath
On Tuesday, 10 July 2012 at 19:27:56 UTC, Namespace wrote: Maybe D need's a readonly keyword. Sometimes i have a class which can take an object from everywhere to store it. So it can not be const, because i didn't just initialized it with a ctor. But i don't want to change the object, i only wa

Re: readonly?

2012-07-10 Thread Simen Kjaeraas
On Tue, 10 Jul 2012 21:27:54 +0200, Namespace wrote: Maybe D need's a readonly keyword. Sometimes i have a class which can take an object from everywhere to store it. So it can not be const, because i didn't just initialized it with a ctor. But i don't want to change the object, i only wa

readonly?

2012-07-10 Thread Namespace
Maybe D need's a readonly keyword. Sometimes i have a class which can take an object from everywhere to store it. So it can not be const, because i didn't just initialized it with a ctor. But i don't want to change the object, i only want to read or call const methods. What now? I'd suggest a

Re: linker error

2012-07-10 Thread lodo
Let suppose I'm writing a library for Win32 applications called "mylibrary". The code of a program, called "UserProgram", that uses this library would be like this: UserProgram.d: import mylibrary; import std.c.windows.windows; int WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR cmdLine,int

Re: linker error

2012-07-10 Thread lodo
Let suppose I'm writing a library for Win32 applications, called "mylibrary". A program, called "UserProgram", that uses this library would be like this: UserProgram.d: import mylibrary; import std.c.windows.windows; int WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR cmdLine,int cmdShow) {

Re: Compilation failure

2012-07-10 Thread Lemonfiend
On Sunday, 8 July 2012 at 22:10:32 UTC, bearophile wrote: When tmp1 is defined globally, dmd is doing something different, in some way it sees global immutables almost as enums... I don't know if this is present in D specs. You see it well with this test program: immutable int[] A = [1]; te

Re: Compilation failure

2012-07-10 Thread Timon Gehr
On 07/08/2012 11:47 PM, Lemonfiend wrote: Hi, I seem to have run into a strange error.. When I put tmp1 outside the main loop, it compiles fine and gives the expected output. When tmp1 is put inside the main loop, the compiler seems to get stuck in a loop? I've tested it on: http://dlang.org/in

Re: Compilation failure

2012-07-10 Thread Lemonfiend
On Sunday, 8 July 2012 at 22:10:32 UTC, bearophile wrote: When tmp1 is defined globally, dmd is doing something different, in some way it sees global immutables almost as enums... I don't know if this is present in D specs. You see it well with this test program: immutable int[] A = [1]; te

Re: Return type inference on template

2012-07-10 Thread Timon Gehr
On 07/10/2012 04:14 PM, Andrea Fontana wrote: Simple template: T test(T)() { return T.init; } This code give error: int myVar; myVar = test(); Why? Can't compiler guess T == int? Type deduction only proceeds in the direction the data flows. Reversing this process would in principle work i

Return type inference on template

2012-07-10 Thread Andrea Fontana
Simple template: T test(T)() { return T.init; } This code give error: int myVar; myVar = test(); Why? Can't compiler guess T == int?