August 09, 2007 Re: Some quick questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Márcio Faustino | Márcio Faustino escribió: > > Another question, why pointers to structs are automatically dereferenced when accessing members, but I cannot use them in "with" statements? For example: > > struct S { > int i; > char c; > } > > S s; > S* ps = &s; > > with (s) {} > with (*ps) {} // Would also be nice if I could do: with (ps) Good question. It has been in the issue database for a while now (http://d.puremagic.com/issues/show_bug.cgi?id=658), but Walter hasn't said anything about it. -- Carlos Santander Bernal |
August 22, 2007 Non-constant expression error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | Hi, Does someone knows why isn't possible to do something like this: //------------------------------------------- import std.regexp; class A { RegExp pattern = new RegExp(".*"); } RegExp[] patterns = [new RegExp(".*")]; //------------------------------------------- Thanks, |
August 22, 2007 Re: Non-constant expression error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Márcio Faustino | "Márcio Faustino" <m.faustino@no.spam.gmail.com> wrote in message news:fah26g$2ctr$1@digitalmars.com... > Hi, > > Does someone knows why isn't possible to do something like this: > > //------------------------------------------- > import std.regexp; > > class A { > RegExp pattern = new RegExp(".*"); > } > > RegExp[] patterns = [new RegExp(".*")]; > //------------------------------------------- > > Thanks, Because those expressions aren't constant. Hate to sound obvious XD You can't use non-constant expressions (like function calls (well.... because of CTFE sometimes those are legal), 'new') as the initializer to globals or class members because the compiler builds up their initializers in the static data segment. Fortunately there are ways to do this: class A { RegExp pattern; this() { // Initialize dynamic members in the constructor. pattern = new RegExp(".*"); } } RegExp[] patterns; static this() { // Initialize dynamic globals in a static constructor. patterns = [new RegExp(".*")]; } |
August 22, 2007 Re: Non-constant expression error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> Because those expressions aren't constant. Hate to sound obvious XD
>
> You can't use non-constant expressions (like function calls (well.... because of CTFE sometimes those are legal), 'new') as the initializer to globals or class members because the compiler builds up their initializers in the static data segment. Fortunately there are ways to do this:
>
> (...)
>
Thanks! ;-)
|
Copyright © 1999-2021 by the D Language Foundation