Several questions (about inline assembly, ddoc for templates, and foreach)

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sat Aug 19 10:22:17 PDT 2006


Marcio wrote:
> Hi all,
> 
> I have several questions I cannot find elsewhere:
> 
> 1 - Using inline assembly, how can I access the "ptr" attribute of an array? For example:
> void main() {
>   int[] array;
>   asm {
>     mov EAX, array.ptr;
>   }
> }
> The compiler says: "identifier expected".

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 ;
#   }
# }

> 2 - Is Ddoc working for templates? If it is, I can't make it generate the documentation for some template functions...
> 
> 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 */
# }

> Thanks,



More information about the Digitalmars-d-learn mailing list