www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to access to struct via pointer.

reply sergey volkovich <sergey.volkovich99 outlook.com> writes:
Hello.
I had next example C code
```c
#include <thread_definitions.h>

struct PROCESS_DATA {
        .... //thread attributes
        };

struct PROCESS_ENTRY{
      PROCESS_ENTRY* next; //must be betree entry
      PROCESS_ENTRY* preview;
   struct PROCESS_DATA process_store;
};

  PROCESS_ENTRY* current_process = kalloc(sizeof(PROCESS_DATA));
bool create_thread_data(){
    ....
    current_process->next = kalloc(sizeof(PROCESS_DATA)); //how to 
implement that stuff
    ....
}
```

can you say, how to rewrite them in d?
Jul 17 2021
next sibling parent Dennis <dkorpel gmail.com> writes:
On Saturday, 17 July 2021 at 11:30:06 UTC, sergey volkovich wrote:
    current_process->next = kalloc(sizeof(PROCESS_DATA)); //how 
 to implement that stuff
A literal translation would be: ```D current_process.next = cast(PROCESS_ENTRY*) kalloc(PROCESS_DATA.sizeof); ``` Though using `PROCESS_DATA.sizeof` for a pointer to a larger structure `PROCESS_ENTRY` looks very sketch, watch that the original C code is correct.
Jul 17 2021
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/17/21 7:30 AM, sergey volkovich wrote:

 can you say, how to rewrite them in d?
Wherever in C or C++ you would use `->`, D uses `.` So `a->member` becomes `a.member`. -Steve
Jul 17 2021