newbie prob: referenced parameter only partially changed

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun May 20 14:58:07 PDT 2007


"J D" <digitalmars at dresserfamily.org> wrote in message 
news:f2qfpf$30d8$1 at digitalmars.com...
> I'll have to remember that, but it stil seems a wee bit inconsistent in 
> that it changes the contents but not the length.

Think of it this way:

void func(int* p)
{
    p = realloc(p, 5);
    p[0] = 4;
}

int* p = new int[2];
p[0] = 2;
func(p);
printf("%d\n", p[0]); // prints 2

Of course, if you're not coming from C, this doesn't help either ;)  But 
whenever you change the length of an array, it can possibly be reallocated 
and moved.

> I am using gdc, and 'inout' worked so I guess it is not the newest.

GDC is only up to DMD 1.004, so no, ref isn't there.

> I tried installing dmd too.  Which is better?  What are the trade-offs?

DMD is kept more up-to-date (it's the reference compiler after all), GDC is 
usually a bit behind.  GDC is available on any platform that GCC is, DMD is 
only available on Windows and Linux.  GDC is completely open-source, DMD has 
a proprietary backend, if you have any ethical qualms about that.

> dmd would not compile the sample code.  It complained of not being able to 
> find libraries even though it was there.

Don't know much about that :{ I think there may have been a topic about 
something like this recently on .learn or .bugs though.. 





More information about the Digitalmars-d mailing list