Re: Structs with pointers?

2011-01-23 Thread Dan Olson
bearophile writes: >> Is this another compiler bug? > > The situation is nice: > > struct Foo1 {} > struct Foo2 { int x; } > const struct Foo3 { int* p; } > struct Foo4 { int* p; } > void bar1(Foo1 f) {} > void bar2(Foo2 f) {} > void bar3(Foo3 f) {} > void bar4(Foo4 f) {} > void main() { > co

Re: Structs with pointers?

2011-01-23 Thread Dmitry Olshansky
On 23.01.2011 19:05, Mafi wrote: Am 23.01.2011 11:00, schrieb Dmitry Olshansky: On 23.01.2011 2:02, bearophile wrote: Is this another compiler bug? The situation is nice: struct Foo1 {} struct Foo2 { int x; } const struct Foo3 { int* p; } struct Foo4 { int* p; } void bar1(Foo1 f) {} void bar2

Re: Structs with pointers?

2011-01-23 Thread Mafi
Am 23.01.2011 11:00, schrieb Dmitry Olshansky: On 23.01.2011 2:02, bearophile wrote: Is this another compiler bug? The situation is nice: struct Foo1 {} struct Foo2 { int x; } const struct Foo3 { int* p; } struct Foo4 { int* p; } void bar1(Foo1 f) {} void bar2(Foo2 f) {} void bar3(Foo3 f) {} v

Re: Structs with pointers?

2011-01-23 Thread bearophile
Dmitry Olshansky: > The first two are actually OK, since you pass a copy of a value type > FooX to barX. > If signature was void bar(ref FooX) then it should have failed. > But the third makes me wonder what the *** is going on. I have added the third case to this bug report of mine: http://d.pu

Re: Structs with pointers?

2011-01-23 Thread Dmitry Olshansky
On 23.01.2011 2:02, bearophile wrote: Is this another compiler bug? The situation is nice: struct Foo1 {} struct Foo2 { int x; } const struct Foo3 { int* p; } struct Foo4 { int* p; } void bar1(Foo1 f) {} void bar2(Foo2 f) {} void bar3(Foo3 f) {} void bar4(Foo4 f) {} void main() { const f1

Re: Structs with pointers?

2011-01-22 Thread bearophile
> Is this another compiler bug? The situation is nice: struct Foo1 {} struct Foo2 { int x; } const struct Foo3 { int* p; } struct Foo4 { int* p; } void bar1(Foo1 f) {} void bar2(Foo2 f) {} void bar3(Foo3 f) {} void bar4(Foo4 f) {} void main() { const f1 = Foo1(); bar1(f1); // no error

Re: Structs with pointers?

2011-01-22 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article > Sean Eskapp: > > Nevermind, I realized it's because constness is transitive in pointers. A > > const > > struct with a pointer member has a const pointer member, and those can't be > > implicitly cast to non-const pointer members. > U

Re: Structs with pointers?

2011-01-22 Thread bearophile
Sean Eskapp: > Nevermind, I realized it's because constness is transitive in pointers. A > const > struct with a pointer member has a const pointer member, and those can't be > implicitly cast to non-const pointer members. Uhm, the struct having a pointer is not important. In theory this too can

Re: Structs with pointers?

2011-01-22 Thread Sean Eskapp
== Quote from Sean Eskapp (eatingstap...@gmail.com)'s article > Why doesn't this code work? > struct Bar > { > int* x; > } > void foo(Bar a) {} > void main() > { > const a = Bar(); > foo(a); > } > But replacing int* with some other type works fine? Even if a write a postblit > fun

Re: Structs with pointers?

2011-01-22 Thread bearophile
Sean Eskapp: > Why doesn't this code work? This works, the Bar instance you give to foo is const. void foo(const Bar a) {} Bye, bearophile

Structs with pointers?

2011-01-22 Thread Sean Eskapp
Why doesn't this code work? struct Bar { int* x; } void foo(Bar a) {} void main() { const a = Bar(); foo(a); } But replacing int* with some other type works fine? Even if a write a postblit function for Bar, it still fails to compile.