Several questions (about inline assembly, ddoc for templates, and foreach)
Marcio
m.faustino at gmail.com
Sat Aug 19 10:43:32 PDT 2006
Chris Nicholson-Sauls wrote:
> (...)
> I'm not sure. Of course, pending a real solution from someone who knows better,
you could
> do this:
>
> # void main () {
> # int[] array ;
> # auto ptr = array.ptr ;
> #
> # asm {
> # mov EAX , ptr ;
> # }
> # }
Yes, that's what I'm doing currently.
> > 3 - Is there a way to manually increment the index of a foreach loop? I ask
this because the index cannot be made inout,
> > only the value.
>
> Any reason why you can't make the index inout? I've done it often enough myself
to this
> very effect. Of course, I'm sure its undefined behavior with associative
arrays, but with
> fixed/variable-length arrays it works just fine.
>
> # int[] arr = someBigFunction();
> #
> # /* skip any values preceded by 0 ... for some reason */
> # foreach (inout i, inout x; arr) {
> # if (i == 0) {
> # i++;
> # continue;
> # }
> # /* do stuff with x */
> # }
Are you sure that works?
I've just tested the following code with DMD v0.164 (in Linux):
void main()
{
char[] arr = "test";
foreach (inout i, inout c; arr) {
if (i == 0) {
i++;
continue;
}
}
}
And the compiler says: "foreach: key cannot be out".
Did you use the last version?
More information about the Digitalmars-d-learn
mailing list