On Saturday, 13 August 2016 at 18:37:54 UTC, Cauterite wrote:
On Saturday, 13 August 2016 at 15:47:51 UTC, D.Rex wrote:
/* memory.d file */
module memory;
import include.linux.sched; /* contains task_struct definition */

void free_page_tables(task_struct* tsk) {
        /* do something with &tsk */
}

And to use the method from somewhere else
/* use method.d */

module usemethod;
import include.linux.sched;
import mm.memory;

void some method() {
        free_page_tables(*pointer to task_struct*);
}

I hope my explanation is not rambling nonsense.

Cheers.

Yes, you're right. Passing structure pointers to functions is an extremely common practice in C, because there aren't really any other compelling options. In D we have things like methods, classes, 'const ref' params, return-type inference, etc., so there's usually a better way to achieve the same result.

Cheers!!

Speaking of classes, and this may have been answered elsewhere, but I am yet to find said answer, or am just missing something right in front of my face...but how does one go about accessing a method from a class if said class is passed to a function as a pointer? By that I mean something like

class Foo {
    void fooMethod() {
    }
}

void bar(Foo *f) {
    /* access fooMethod from &f */
}

Thanks for all your help, I really appreciate it!!

Reply via email to