Re: Passing Structs to function like in C

2016-08-14 Thread Cauterite via Digitalmars-d-learn
On Sunday, 14 August 2016 at 16:21:58 UTC, D.Rex wrote: so '();' works the same as 'foo.bar();'? with pointers, D automatically rewrites expressions like this: f.fooMethod() to this: (*f).fooMethod() which is why you're able to index an object-pointer-pointer (Foo*) the same

Re: Passing Structs to function like in C

2016-08-14 Thread D.Rex via Digitalmars-d-learn
On Sunday, 14 August 2016 at 14:59:17 UTC, Adam D. Ruppe wrote: On Sunday, 14 August 2016 at 14:54:27 UTC, D.Rex wrote: 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

Re: Passing Structs to function like in C

2016-08-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 August 2016 at 14:54:27 UTC, D.Rex wrote: 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

Re: Passing Structs to function like in C

2016-08-14 Thread D.Rex via Digitalmars-d-learn
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

Re: Passing Structs to function like in C

2016-08-14 Thread D.Rex via Digitalmars-d-learn
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

Re: Passing Structs to function like in C

2016-08-13 Thread ag0aep6g via Digitalmars-d-learn
On 08/13/2016 09:23 PM, Engine Machine wrote: Then it should error if it doesn't accept ';'. If it accepts it then it is legal. It is legal, yes. It's also pointless and misleading. It should be pointed out for the benefit of the author, as they may have a misconception about D syntax. It

Re: Passing Structs to function like in C

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 17:53:12 UTC, ag0aep6g wrote: On 08/12/2016 07:33 PM, Cauterite wrote: Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not tell the lexer precisely

Re: Passing Structs to function like in C

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 18:23:55 UTC, Cauterite wrote: Thanks colon-nazis, I'll take that into consideration ¬_¬ Be careful! They will cauterize your testicles and rape your children! Those semi-clone, I mean semi-colon-nazis are the worse kind! It's a life and death matter! After all,

Re: Passing Structs to function like in C

2016-08-13 Thread Cauterite via Digitalmars-d-learn
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 */ } And to use the method from somewhere else /* use

Re: Passing Structs to function like in C

2016-08-12 Thread cy via Digitalmars-d-learn
On Friday, 12 August 2016 at 15:21:22 UTC, D.Rex wrote: I was wondering how this is achieved in D, or if D has an alternative implementation of this. It isn't, because C interfaces that require you to pass in structures are inherently bad design, and usually both unstable and extremely C

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
Thanks colon-nazis, I'll take that into consideration ¬_¬

Re: Passing Structs to function like in C

2016-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2016 07:33 PM, Cauterite wrote: Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not tell the lexer precisely where my declaration ends instead of relying on whatever other

Re: Passing Structs to function like in C

2016-08-12 Thread WebFreak001 via Digitalmars-d-learn
On Friday, 12 August 2016 at 17:33:34 UTC, Cauterite wrote: On Friday, 12 August 2016 at 16:50:43 UTC, ag0aep6g wrote: On 08/12/2016 05:23 PM, Cauterite wrote: No semicolon there, please. Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
On Friday, 12 August 2016 at 16:50:43 UTC, ag0aep6g wrote: On 08/12/2016 05:23 PM, Cauterite wrote: No semicolon there, please. Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not

Re: Passing Structs to function like in C

2016-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2016 05:23 PM, Cauterite wrote: void main() { [...] }; No semicolon there, please.

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
On Friday, 12 August 2016 at 15:21:22 UTC, D.Rex wrote: extern unsigned long free_page_tables(struct task_struct * tsk); extern(C) ulong free_page_tables(task_struct* tsk); void main() { task_struct tsk = …… ; free_page_tables(); }; That should be what you're after?

Passing Structs to function like in C

2016-08-12 Thread D.Rex via Digitalmars-d-learn
Hi, This has probably been asked many times before, but after search for hours and hours I can't find an answer. I have seen in C an extern function taking in a struct as one of its parameters, like so: extern unsigned long free_page_tables(struct task_struct * tsk); I was wondering how