www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pointers to structures

reply DLearner <bmqazwsx123 gmail.com> writes:
Could it be made acceptable, at least for -betterC option, to use 
'->' as an alternative to '.'?

'ptrStructVar->MemOfStructVar' is a very common idiom in C.

Best regards
Mar 19 2021
next sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Friday, 19 March 2021 at 11:23:36 UTC, DLearner wrote:
 Could it be made acceptable, at least for -betterC option, to 
 use '->' as an alternative to '.'?

 'ptrStructVar->MemOfStructVar' is a very common idiom in C.

 Best regards
You could try search and replace '->' with '.' see how it goes
Mar 19 2021
prev sibling parent reply Cym13 <cpicard purrfect.fr> writes:
On Friday, 19 March 2021 at 11:23:36 UTC, DLearner wrote:
 Could it be made acceptable, at least for -betterC option, to 
 use '->' as an alternative to '.'?

 'ptrStructVar->MemOfStructVar' is a very common idiom in C.

 Best regards
In D '.' can be used to access the member of a struct regardless of whether you are manipulating the struct itself or a pointer to that struct. So you can just write 'ptrStructVar.MemOfStructVar' and it will work without any issue.
Mar 19 2021
parent reply novice3 <sorryno em.ail> writes:
On Friday, 19 March 2021 at 12:19:47 UTC, Cym13 wrote:
 In D '.' can be used to access the member of a struct 
 regardless of whether you are manipulating the struct itself or 
 a pointer to that struct. So you can just write 
 'ptrStructVar.MemOfStructVar' and it will work without any 
 issue.
i guess, idea was to reduce manual work then adapt C sources to D. i have similar wishes for "typedef ...". it is boring to rewrite it then making C binding.
Mar 19 2021
parent ryuukk_ <ryuukk_ gmail.com> writes:
On Friday, 19 March 2021 at 13:15:16 UTC, novice3 wrote:
 On Friday, 19 March 2021 at 12:19:47 UTC, Cym13 wrote:
 In D '.' can be used to access the member of a struct 
 regardless of whether you are manipulating the struct itself 
 or a pointer to that struct. So you can just write 
 'ptrStructVar.MemOfStructVar' and it will work without any 
 issue.
i guess, idea was to reduce manual work then adapt C sources to D. i have similar wishes for "typedef ...". it is boring to rewrite it then making C binding.
Nobody needs to manually write bindings nowadays https://github.com/jacob-carlborg/dstep I use it to generate the bindings of the C headers libs i need Works most of the time, sometimes i have to do some cleanup, but it's faster than doing all the thing manually Alternatively one can use dpp https://github.com/atilaneves/dpp
Mar 19 2021