Passing Structs to function like in C

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 13 11:37:54 PDT 2016


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.


More information about the Digitalmars-d-learn mailing list