August 09, 2007
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
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
"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
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! ;-)
1 2
Next ›   Last »