www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - betterC and struct destructors

reply Oleg B <code.viator gmail.com> writes:
Hello. I try using destructor in betterC code and it's work if 
outer function doesn't return value (void). Code in `scope 
(exit)` works as same (if func is void all is ok).

In documentation I found 
https://dlang.org/spec/betterc.html#consequences 12 paragraph: 
Struct deconstructors.

Why struct destructor need Druntime? Compiler must simply past 
call of destructor before exit from scope or return statement. 
Where is Druntime here (dynamic allocations, pointers to scopes 
and other)?

I think struct destructor must work in betterC code. Otherwise it 
will be one step to be likeC, not betterC.
Sep 11
next sibling parent Vadim Lopatin <coolreader.org gmail.com> writes:
On Monday, 11 September 2017 at 10:18:41 UTC, Oleg B wrote:
 Hello. I try using destructor in betterC code and it's work if 
 outer function doesn't return value (void). Code in `scope 
 (exit)` works as same (if func is void all is ok).

 In documentation I found 
 https://dlang.org/spec/betterc.html#consequences 12 paragraph: 
 Struct deconstructors.

 Why struct destructor need Druntime? Compiler must simply past 
 call of destructor before exit from scope or return statement. 
 Where is Druntime here (dynamic allocations, pointers to scopes 
 and other)?

 I think struct destructor must work in betterC code. Otherwise 
 it will be one step to be likeC, not betterC.
+1 I don't see the reason. If struct destructors were working correctly in betterC mode, it would be possible to use RAII. Missing RAII is a main reason of WTF messages when people see list of betterC limitations.
Sep 11
prev sibling parent Moritz Maxeiner <moritz ucworks.org> writes:
On Monday, 11 September 2017 at 10:18:41 UTC, Oleg B wrote:
 Hello. I try using destructor in betterC code and it's work if 
 outer function doesn't return value (void). Code in `scope 
 (exit)` works as same (if func is void all is ok).

 In documentation I found 
 https://dlang.org/spec/betterc.html#consequences 12 paragraph: 
 Struct deconstructors.

 [...]
It's an implementation isssue [1][2][3]. [1] https://issues.dlang.org/show_bug.cgi?id=17603 [2] https://github.com/dlang/dmd/pull/6923 [3] https://www.reddit.com/r/programming/comments/6ijwek/dlangs_dmd_now_compiles_programs_in_betterc_mode/dj7dncc/
Sep 11