Array access via pointer

Simen kjaeraas simen.kjaras at gmail.com
Sun May 30 14:09:10 PDT 2010


Robert <robert.muench at robertmuench.de> wrote:

> Ah, I was looking for something like this but didn't find it.
>
> Do all variables and types support the .ptr property?

Nope. Arrays do, as they are simply C arrays (T*) with a length
attached, and some fancy goings-on behind the scenes.

Basically, in C, the equivalent would be

typedef struct array {
     int* ptr;
     int length;
};

If I wanted something other than an array, such a structure
makes little sense. Especially seeing as most anything other
than a dynamic array could be stack-allocated, and we don't
want any pointers to stack stuff to escape for long.

-- 
Simen


More information about the Digitalmars-d mailing list